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.

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

The owner of the record. For example: example.com.. (String)

type

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

ttl

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

data

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.”]. (String or Array of String)



89
90
91
92
93
94
95
96
97
98
# File 'lib/gcloud/dns/record.rb', line 89

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

#dataObject

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



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

def data
  @data
end

#nameObject

The owner of the record. For example: example.com.. (String)



45
46
47
# File 'lib/gcloud/dns/record.rb', line 45

def name
  @name
end

#ttlObject

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



56
57
58
# File 'lib/gcloud/dns/record.rb', line 56

def ttl
  @ttl
end

#typeObject

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



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

def type
  @type
end

Class Method Details

.from_gapi(gapi) ⇒ Object

New Record from a Google API Client object.



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

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

Instance Method Details

#<=>(other) ⇒ Object

:nodoc:



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

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

#==(other) ⇒ Object

:nodoc:



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

def == other #:nodoc:
  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.



113
114
115
116
117
# File 'lib/gcloud/dns/record.rb', line 113

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

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


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

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

#hashObject

:nodoc:



131
132
133
# File 'lib/gcloud/dns/record.rb', line 131

def hash #:nodoc:
  [name, type, ttl, data].hash
end

#to_gapiObject

Convert the record object to a Google API hash.



127
128
129
# File 'lib/gcloud/dns/record.rb', line 127

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

#to_zonefile_recordsObject

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



103
104
105
106
107
# File 'lib/gcloud/dns/record.rb', line 103

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