Class: Dslimple::Record

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#contentObject

Returns the value of attribute content.



8
9
10
# File 'lib/dslimple/record.rb', line 8

def content
  @content
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/dslimple/record.rb', line 8

def id
  @id
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/dslimple/record.rb', line 8

def name
  @name
end

#priorityObject

Returns the value of attribute priority.



8
9
10
# File 'lib/dslimple/record.rb', line 8

def priority
  @priority
end

#regionsObject

Returns the value of attribute regions.



8
9
10
# File 'lib/dslimple/record.rb', line 8

def regions
  @regions
end

#system_recordObject

Returns the value of attribute system_record.



8
9
10
# File 'lib/dslimple/record.rb', line 8

def system_record
  @system_record
end

#ttlObject

Returns the value of attribute ttl.



8
9
10
# File 'lib/dslimple/record.rb', line 8

def ttl
  @ttl
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/dslimple/record.rb', line 8

def type
  @type
end

#zoneObject

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

#hashObject



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(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_paramsObject



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