class Google::Cloud::Dns::Record

# DNS Record

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

@example

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

Attributes

data[RW]

The array of resource record data, as determined by `type` and defined in [RFC 1035 (section 5)](tools.ietf.org/html/rfc1035#section-5) and [RFC 1034 (section 3.6.1)](tools.ietf.org/html/rfc1034#section-3.6.1). For example: [“10 mail.example.com.”, “20 mail2.example.com.”].

@return [Array<String>]

name[RW]

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

@return [String]

ttl[RW]

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

@return [Integer]

type[RW]

The identifier of a [supported record type ](cloud.google.com/dns/what-is-cloud-dns#supported_record_types). For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.

@return [String]

Public Class Methods

from_gapi(gapi) click to toggle source

@private New Record from a Google API Client object.

# File lib/google/cloud/dns/record.rb, line 130
def self.from_gapi gapi
  new gapi.name, gapi.type, gapi.ttl, gapi.rrdatas
end
new(name, type, ttl, data) click to toggle source

Creates a Record value object.

@param [String] name The owner of the record. For example:

`example.com.`.

@param [String] type The identifier of a [supported record

type](https://cloud.google.com/dns/what-is-cloud-dns).
For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.

@param [Integer] ttl The number of seconds that the record can be

cached by resolvers.

@param [String, Array<String>] data The resource record data, as

determined by `type` and defined in [RFC
1035 (section 5)](http://tools.ietf.org/html/rfc1035#section-5) and
[RFC 1034
(section 3.6.1)](http://tools.ietf.org/html/rfc1034#section-3.6.1).
For example: ["10 mail.example.com.", "20 mail2.example.com."].
# File lib/google/cloud/dns/record.rb, line 97
def initialize name, type, ttl, data
  raise ArgumentError, "name is required" unless name
  raise ArgumentError, "type is required" unless type
  raise ArgumentError, "ttl is required" unless ttl
  raise ArgumentError, "data is required" unless data
  @name = name.to_s
  @type = type.to_s.upcase
  @ttl = Integer(ttl)
  @data = Array(data)
end

Public Instance Methods

<=>(other) click to toggle source

@private

# File lib/google/cloud/dns/record.rb, line 161
def <=> other
  return nil unless other.is_a? self.class
  [name, type, ttl, data] <=>
    [other.name, other.type, other.ttl, other.data]
end
==(other)

@private

Alias for: eql?
dup() click to toggle source

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

Calls superclass method
# File lib/google/cloud/dns/record.rb, line 122
def dup
  other = super
  other.data = data.map(&:dup)
  other
end
eql?(other) click to toggle source

@private

# File lib/google/cloud/dns/record.rb, line 152
def eql? other
  return false unless other.is_a? self.class
  name == other.name && type == other.type &&
    ttl == other.ttl && data == other.data
end
Also aliased as: ==
hash() click to toggle source

@private

# File lib/google/cloud/dns/record.rb, line 147
def hash
  [name, type, ttl, data].hash
end
to_gapi() click to toggle source

@private Convert the record object to a Google API hash.

# File lib/google/cloud/dns/record.rb, line 136
def to_gapi
  Google::Apis::DnsV1::ResourceRecordSet.new(
    kind: "dns#resourceRecordSet",
    name: name,
    rrdatas: data,
    ttl: ttl,
    type: type
  )
end
to_zonefile_records() click to toggle source

@private Returns an array of strings in the zone file format, one for each element in the record's data array.

# File lib/google/cloud/dns/record.rb, line 111
def to_zonefile_records
  data.map do |rrdata|
    "#{name} #{ttl} IN #{type} #{rrdata}"
  end
end