Class: Google::Cloud::Dns::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/dns/record.rb,
lib/google/cloud/dns/record/list.rb

Overview

DNS Record

Represents a set of DNS resource records (RRs) for a given #name and #type in a Zone. Since it is a value object, a newly created Record instance is transient until it is added to a Zone with Zone#update. Note that Zone#add and the Zone#update block parameter can be used instead of Zone#record or Record.new to create new records.

Examples:

require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"

zone.records.count #=> 2
record = zone.record "example.com.", "A", 86400, "1.2.3.4"
zone.records.count #=> 2
change = zone.update record
zone.records.count #=> 3

Defined Under Namespace

Classes: List

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, ttl, data) ⇒ Record

Creates a Record value object.

Parameters:

  • name (String)

    The owner of the record. For example: example.com..

  • type (String)

    The identifier of a supported record type. For example: A, AAAA, CNAME, MX, or TXT.

  • ttl (Integer)

    The number of seconds that the record can be cached by resolvers.

  • data (String, Array<String>)

    The resource record data, as determined by type and defined in RFC 1035 (section 5) and RFC 1034 (section 3.6.1). For example: ["10 mail.example.com.", "20 mail2.example.com."].



97
98
99
100
101
102
103
104
105
106
# File 'lib/google/cloud/dns/record.rb', line 97

def initialize name, type, ttl, data
  fail ArgumentError, "name is required" unless name
  fail ArgumentError, "type is required" unless type
  fail ArgumentError, "ttl is required" unless ttl
  fail ArgumentError, "data is required" unless data
  @name = name.to_s
  @type = type.to_s.upcase
  @ttl = Integer(ttl)
  @data = Array(data)
end

Instance Attribute Details

#dataArray<String>

The array of resource record data, as determined by type and defined in RFC 1035 (section 5) and RFC 1034 (section 3.6.1). For example: ["10 mail.example.com.", "20 mail2.example.com."].

Returns:

  • (Array<String>)


78
79
80
# File 'lib/google/cloud/dns/record.rb', line 78

def data
  @data
end

#nameString

The owner of the record. For example: example.com..

Returns:

  • (String)


51
52
53
# File 'lib/google/cloud/dns/record.rb', line 51

def name
  @name
end

#ttlInteger

The number of seconds that the record can be cached by resolvers.

Returns:

  • (Integer)


67
68
69
# File 'lib/google/cloud/dns/record.rb', line 67

def ttl
  @ttl
end

#typeString

The identifier of a supported record type . For example: A, AAAA, CNAME, MX, or TXT.

Returns:

  • (String)


60
61
62
# File 'lib/google/cloud/dns/record.rb', line 60

def type
  @type
end

Instance Method Details

#dupObject

Returns a deep copy of the record. Useful for updating records, since the original, unmodified record must be passed for deletion when using Zone#update.



122
123
124
125
126
# File 'lib/google/cloud/dns/record.rb', line 122

def dup
  other = super
  other.data = data.map(&:dup)
  other
end