Class: ProviderDSL::Record
- Inherits:
-
Object
- Object
- ProviderDSL::Record
- Defined in:
- lib/provider_dsl/record.rb
Overview
Manage a DNS record
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #===(other) ⇒ Object
-
#initialize(name, type, values, ttl) ⇒ Record
constructor
A new instance of Record.
- #same_name_and_type(other) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, type, values, ttl) ⇒ Record
Returns a new instance of Record.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/provider_dsl/record.rb', line 6 def initialize(name, type, values, ttl) @name = name @type = type @values = Array(values).map do |value| case type when 'AAAA' raise "#{value} is not a valid IPv6 address" unless IPAddress.valid_ipv6?(value) IPAddress(value).compressed when 'A' raise "#{value} is not a valid IPv4 address" unless IPAddress.valid_ipv4?(value) IPAddress(value).octets.join('.') when 'CNAME', 'MX', 'TXT' value else raise "Record #{name} #{type} has unhandled type" end end.uniq.sort @ttl = ttl raise "No values for record #{self}" if @values.empty? return unless type == 'CNAME' raise "Record #{self} must have only one value" if @values.count != 1 raise "Record #{self} is invalid on the naked domain" if name == '@' end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/provider_dsl/record.rb', line 4 def name @name end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
4 5 6 |
# File 'lib/provider_dsl/record.rb', line 4 def ttl @ttl end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/provider_dsl/record.rb', line 4 def type @type end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
4 5 6 |
# File 'lib/provider_dsl/record.rb', line 4 def values @values end |
Instance Method Details
#==(other) ⇒ Object
34 35 36 |
# File 'lib/provider_dsl/record.rb', line 34 def ==(other) self === other && ttl == other.ttl end |
#===(other) ⇒ Object
38 39 40 |
# File 'lib/provider_dsl/record.rb', line 38 def ===(other) same_name_and_type(other) && values == other.values end |
#same_name_and_type(other) ⇒ Object
42 43 44 |
# File 'lib/provider_dsl/record.rb', line 42 def same_name_and_type(other) name == other.name && type == other.type end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/provider_dsl/record.rb', line 30 def to_s "#{ttl} #{name} #{type} #{values}" end |