class Dslimple::Record
Constants
- DEFAULT_REGIONS
- RECORD_TYPES
Attributes
content[RW]
id[RW]
name[RW]
priority[RW]
regions[RW]
system_record[RW]
ttl[RW]
type[RW]
zone[RW]
Public Class Methods
new(attrs = {})
click to toggle source
# 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
Public Instance Methods
==(other)
click to toggle source
# File lib/dslimple/record.rb, line 37 def ==(other) other.is_a?(self.class) && hash == other.hash end
===(other)
click to toggle source
# 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)
click to toggle source
# File lib/dslimple/record.rb, line 25 def [](key) send(key) end
child_record?()
click to toggle source
# File lib/dslimple/record.rb, line 33 def child_record? !@parent_id.nil? end
hash()
click to toggle source
# File lib/dslimple/record.rb, line 45 def hash [zone.to_s, name, type, ttl, priority, content, regions, !!system_record].hash end
system_record?()
click to toggle source
# File lib/dslimple/record.rb, line 29 def system_record? @system_record == true end
to_dsl(options = {})
click to toggle source
# File lib/dslimple/record.rb, line 49 def to_dsl(options = {}) [ " #{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()
click to toggle source
# 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
Private Instance Methods
normalize_attrs(record)
click to toggle source
# File lib/dslimple/record.rb, line 77 def normalize_attrs(record) attrs = {} record.instance_variables.each do |var| attrs[:"#{var.to_s.sub(/^@/, '')}"] = record.instance_variable_get(var) end attrs end