Class: DnsMadeEasy::Zone::Parser

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

Overview

Parses standard zone-file text into provider-neutral records.

Constant Summary collapse

SUPPORTED_RECORD_CLASSES =
{
  'DNS::Zonefile::A' => 'A',
  'DNS::Zonefile::AAAA' => 'AAAA',
  'DNS::Zonefile::CNAME' => 'CNAME',
  'DNS::Zonefile::MX' => 'MX',
  'DNS::Zonefile::NS' => 'NS',
  'DNS::Zonefile::PTR' => 'PTR',
  'DNS::Zonefile::SPF' => 'SPF',
  'DNS::Zonefile::SRV' => 'SRV',
  'DNS::Zonefile::TXT' => 'TXT'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(zone_text) ⇒ Parser

Returns a new instance of Parser.



27
28
29
# File 'lib/dnsmadeeasy/zone/parser.rb', line 27

def initialize(zone_text)
  @zone_text = zone_text
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
38
39
# File 'lib/dnsmadeeasy/zone/parser.rb', line 31

def call
  zone = DNS::Zonefile.load(parseable_zone_text)
  records, errors = build_records(zone)
  return Failure(errors) if errors.any?

  Success(File.new(origin: zone_origin(zone), ttl: zone_ttl(zone), record_set: RecordSet.new(records: records)))
rescue DNS::Zonefile::ParsingError, DNS::Zonefile::UnknownRecordType, Dry::Struct::Error => e
  Failure([e.message])
end