Class: Zonesync::Parser::Zone

Inherits:
Object
  • Object
show all
Defined in:
lib/zonesync/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries, origin: nil, alternate_origin: ".") ⇒ Zone

Returns a new instance of Zone.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/zonesync/parser.rb', line 28

def initialize(entries, origin: nil, alternate_origin: ".")
  @origin = origin
  @records = []
  @vars = {"origin" => alternate_origin, :last_host => "."}
  entries.each do |e|
    case e.parse_type
    when :variable
      key = e.name.text_value.downcase
      @vars[key] = case key
      when "ttl"
        e.value.text_value.to_i
      else
        e.value.text_value
      end
    when :soa
      @records << SOA.new(@vars, e)
    when :record
      case e.record_type
      when "A" then @records << A.new(@vars, e)
      when "AAAA" then @records << AAAA.new(@vars, e)
      when "CAA" then @records << CAA.new(@vars, e)
      when "CNAME" then @records << CNAME.new(@vars, e)
      when "MX" then @records << MX.new(@vars, e)
      when "NAPTR" then @records << NAPTR.new(@vars, e)
      when "NS" then @records << NS.new(@vars, e)
      when "PTR" then @records << PTR.new(@vars, e)
      when "SRV" then @records << SRV.new(@vars, e)
      when "SPF" then @records << SPF.new(@vars, e)
      when "SSHFP" then @records << SSHFP.new(@vars, e)
      when "TXT" then @records << TXT.new(@vars, e)
      when "SOA" then
        # No-op
      else
        raise UnknownRecordType, "Unknown record type: #{e.record_type}"
      end
    end
  end
  @origin ||= soa.origin
end

Instance Attribute Details

#originObject (readonly)

Returns the value of attribute origin.



24
25
26
# File 'lib/zonesync/parser.rb', line 24

def origin
  @origin
end

#recordsObject (readonly)

Returns the value of attribute records.



26
27
28
# File 'lib/zonesync/parser.rb', line 26

def records
  @records
end

Instance Method Details

#records_of(kl) ⇒ Object



72
73
74
# File 'lib/zonesync/parser.rb', line 72

def records_of(kl)
  @records.select { |r| r.instance_of? kl }
end

#soaObject



68
69
70
# File 'lib/zonesync/parser.rb', line 68

def soa
  records_of(SOA).first
end