Class: Dslimple::Record
- Inherits:
-
Object
- Object
- Dslimple::Record
- Defined in:
- lib/dslimple/record.rb
Constant Summary collapse
- RECORD_TYPES =
%w[A ALIAS CNAME MX SPF URL TXT NS SRV NAPTR PTR AAAA SSHFP HINFO POOL CAA]- DEFAULT_REGIONS =
['global']
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#regions ⇒ Object
Returns the value of attribute regions.
-
#system_record ⇒ Object
Returns the value of attribute system_record.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
-
#type ⇒ Object
Returns the value of attribute type.
-
#zone ⇒ Object
Returns the value of attribute zone.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #===(other) ⇒ Object
- #[](key) ⇒ Object
- #child_record? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(attrs = {}) ⇒ Record
constructor
A new instance of Record.
- #system_record? ⇒ Boolean
- #to_dsl(options = {}) ⇒ Object
- #to_params ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Record
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dslimple/record.rb', line 10 def initialize(attrs = {}) attrs = normalize_attrs(attrs) if attrs.is_a?(Dnsimple::Struct::ZoneRecord) @id = attrs[:id] @zone = attrs[:zone_id] || attrs[:zone] @name = attrs[:name] @type = attrs[:type].to_s.downcase.to_sym @ttl = attrs[:ttl] @parent_id = attrs[:parent_id] @priority = attrs[:priority] @content = attrs[:content] @regions = attrs[:regions] || DEFAULT_REGIONS @system_record = attrs[:system_record] end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
8 9 10 |
# File 'lib/dslimple/record.rb', line 8 def content @content end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/dslimple/record.rb', line 8 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/dslimple/record.rb', line 8 def name @name end |
#priority ⇒ Object
Returns the value of attribute priority.
8 9 10 |
# File 'lib/dslimple/record.rb', line 8 def priority @priority end |
#regions ⇒ Object
Returns the value of attribute regions.
8 9 10 |
# File 'lib/dslimple/record.rb', line 8 def regions @regions end |
#system_record ⇒ Object
Returns the value of attribute system_record.
8 9 10 |
# File 'lib/dslimple/record.rb', line 8 def system_record @system_record end |
#ttl ⇒ Object
Returns the value of attribute ttl.
8 9 10 |
# File 'lib/dslimple/record.rb', line 8 def ttl @ttl end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/dslimple/record.rb', line 8 def type @type end |
#zone ⇒ Object
Returns the value of attribute zone.
8 9 10 |
# File 'lib/dslimple/record.rb', line 8 def zone @zone end |
Instance Method Details
#==(other) ⇒ Object
37 38 39 |
# File 'lib/dslimple/record.rb', line 37 def ==(other) other.is_a?(self.class) && hash == other.hash end |
#===(other) ⇒ Object
41 42 43 |
# File 'lib/dslimple/record.rb', line 41 def ===(other) other.is_a?(self.class) && i[zone name type content].all? { |attr| send(attr).to_s == other.send(attr).to_s } end |
#[](key) ⇒ Object
25 26 27 |
# File 'lib/dslimple/record.rb', line 25 def [](key) send(key) end |
#child_record? ⇒ Boolean
33 34 35 |
# File 'lib/dslimple/record.rb', line 33 def child_record? !@parent_id.nil? end |
#hash ⇒ Object
45 46 47 |
# File 'lib/dslimple/record.rb', line 45 def hash [zone.to_s, name, type, ttl, priority, content, regions, !!system_record].hash end |
#system_record? ⇒ Boolean
29 30 31 |
# File 'lib/dslimple/record.rb', line 29 def system_record? @system_record == true end |
#to_dsl(options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dslimple/record.rb', line 49 def to_dsl( = {}) [ " #{type.to_s.downcase}_record(#{name.inspect}) do", priority ? " priority #{priority.inspect}" : "", ttl ? " ttl #{ttl}" : "", regions != DEFAULT_REGIONS ? " regions #{regions.inspect}" : "", " content #{content.inspect}", " end", ].reject(&:empty?).join("\n") end |
#to_params ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dslimple/record.rb', line 60 def to_params params = { id: @id, name: name, type: type.to_s.upcase, content: content, ttl: ttl, priority: priority, regions: regions, } params.delete(:regions) params end |