Class: Gcloud::Dns::Record
- Inherits:
-
Object
- Object
- Gcloud::Dns::Record
- 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.
Defined Under Namespace
Classes: List
Instance Attribute Summary collapse
-
#data ⇒ Array<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).
-
#name ⇒ String
The owner of the record.
-
#ttl ⇒ Integer
The number of seconds that the record can be cached by resolvers.
-
#type ⇒ String
The identifier of a [supported record type ](cloud.google.com/dns/what-is-cloud-dns#supported_record_types) .
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#dup ⇒ Object
Returns a deep copy of the record.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name, type, ttl, data) ⇒ Record
constructor
Creates a Record value object.
- #to_gapi ⇒ Object
-
#to_zonefile_records ⇒ Object
for each element in the record’s data array.
Constructor Details
#initialize(name, type, ttl, data) ⇒ Record
Creates a Record value object.
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
#data ⇒ Array<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.”].
77 78 79 |
# File 'lib/gcloud/dns/record.rb', line 77 def data @data end |
#name ⇒ String
The owner of the record. For example: ‘example.com.`.
50 51 52 |
# File 'lib/gcloud/dns/record.rb', line 50 def name @name end |
#ttl ⇒ Integer
The number of seconds that the record can be cached by resolvers.
66 67 68 |
# File 'lib/gcloud/dns/record.rb', line 66 def ttl @ttl end |
#type ⇒ String
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`.
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
163 164 165 166 167 |
# File 'lib/gcloud/dns/record.rb', line 163 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
158 159 160 |
# File 'lib/gcloud/dns/record.rb', line 158 def == other self.eql? other end |
#dup ⇒ Object
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
151 152 153 154 155 |
# File 'lib/gcloud/dns/record.rb', line 151 def eql? other return false unless other.is_a? self.class name == other.name && type == other.type && ttl == other.ttl && data == other.data end |
#hash ⇒ Object
146 147 148 |
# File 'lib/gcloud/dns/record.rb', line 146 def hash [name, type, ttl, data].hash end |
#to_gapi ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/gcloud/dns/record.rb', line 135 def to_gapi Google::Apis::DnsV1::ResourceRecordSet.new( kind: "dns#resourceRecordSet", name: name, rrdatas: data, ttl: ttl, type: type ) end |
#to_zonefile_records ⇒ Object
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 |