Class: Gcloud::Dns::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/dns/record.rb,
lib/gcloud/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 "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
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

Class Method 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](cloud.google.com/dns/what-is-cloud-dns). 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)](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.”].



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

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)](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.”].

Returns:

  • (Array<String>)


77
78
79
# File 'lib/gcloud/dns/record.rb', line 77

def data
  @data
end

#nameString

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

Returns:

  • (String)


50
51
52
# File 'lib/gcloud/dns/record.rb', line 50

def name
  @name
end

#ttlInteger

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

Returns:

  • (Integer)


66
67
68
# File 'lib/gcloud/dns/record.rb', line 66

def ttl
  @ttl
end

#typeString

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`.

Returns:

  • (String)


59
60
61
# File 'lib/gcloud/dns/record.rb', line 59

def type
  @type
end

Class Method Details

.from_gapi(gapi) ⇒ Object



129
130
131
# File 'lib/gcloud/dns/record.rb', line 129

def self.from_gapi gapi
  new gapi["name"], gapi["type"], gapi["ttl"], gapi["rrdatas"]
end

Instance Method Details

#<=>(other) ⇒ Object



157
158
159
160
161
# File 'lib/gcloud/dns/record.rb', line 157

def <=> other
  return nil unless other.is_a? self.class
  [name, type, ttl, data] <=>
    [other.name, other.type, other.ttl, other.data]
end

#==(other) ⇒ Object



152
153
154
# File 'lib/gcloud/dns/record.rb', line 152

def == other
  self.eql? other
end

#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.



121
122
123
124
125
# File 'lib/gcloud/dns/record.rb', line 121

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


145
146
147
148
149
# File 'lib/gcloud/dns/record.rb', line 145

def eql? other
  return false unless other.is_a? self.class
  name == other.name && type == other.type &&
    ttl == other.ttl && data == other.data
end

#hashObject



140
141
142
# File 'lib/gcloud/dns/record.rb', line 140

def hash
  [name, type, ttl, data].hash
end

#to_gapiObject



135
136
137
# File 'lib/gcloud/dns/record.rb', line 135

def to_gapi
  { "name" => name, "type" => type, "ttl" => ttl, "rrdatas" => data }
end

#to_zonefile_recordsObject

for each element in the record’s data array.



110
111
112
113
114
# File 'lib/gcloud/dns/record.rb', line 110

def to_zonefile_records
  data.map do |rrdata|
    "#{name} #{ttl} IN #{type} #{rrdata}"
  end
end