Class: Dnsdeploy::Local

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsdeploy/local.rb

Instance Method Summary collapse

Constructor Details

#initialize(local_records_json) ⇒ Local

Returns a new instance of Local.



5
6
7
# File 'lib/dnsdeploy/local.rb', line 5

def initialize(local_records_json)
  @local_records_json = local_records_json
end

Instance Method Details

#all_recordsObject



9
10
11
12
13
14
# File 'lib/dnsdeploy/local.rb', line 9

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

#create_records(domain, json_records) ⇒ Object



26
27
28
29
30
31
# File 'lib/dnsdeploy/local.rb', line 26

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

#dnsimple_domain(zone) ⇒ Object



37
38
39
40
# File 'lib/dnsdeploy/local.rb', line 37

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

#domainsObject



20
21
22
23
24
# File 'lib/dnsdeploy/local.rb', line 20

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

#jsonObject



33
34
35
# File 'lib/dnsdeploy/local.rb', line 33

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

#records(domain) ⇒ Object



16
17
18
# File 'lib/dnsdeploy/local.rb', line 16

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