Sha256: 04cf9fbc310e317566fc4bd7e993a55f6c427edc1d3b4433ccf1ba496a6ace5d

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

require 'singleton'

module Dnsdeploy
  class Local
    def initialize(local_records_json)
      @local_records_json = local_records_json
    end

    def all_records
      @all_records ||= json.map do |record_set|
        domain = dnsimple_domain(record_set['zone'])
        create_records(domain, record_set['records'])
      end.flatten
    end

    def records(domain)
      all_records.select { |r| r.domain.name == domain.name }
    end

    def domains
      @domains ||= json.map do |record_set|
        domain = dnsimple_domain(record_set['zone'])
      end
    end

    def create_records(domain, json_records)
      json_records.map do |record|
        Record.new(domain: domain, name: record['name'], record_type: record['type'],
          content: record['value'], ttl: record['ttl'], prio: record['prio'])
      end
    end

    def json
      @json ||= JSON.load(@local_records_json)
    end

    def dnsimple_domain(zone)
      @dnsimple_domains ||= {}
      @dnsimple_domains[zone] ||= DNSimple::Domain.all.select { |d| d.name == zone }.first
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dnsdeploy-0.0.3 lib/dnsdeploy/local.rb
dnsdeploy-0.0.2 lib/dnsdeploy/local.rb