Class: Dnsdeploy::Base

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records_file_path) ⇒ Base

Returns a new instance of Base.



3
4
5
6
# File 'lib/dnsdeploy/base.rb', line 3

def initialize(records_file_path)
  @records_file_path = records_file_path
  @local_records_json = File.new(records_file_path).read
end

Class Method Details

.update_records(records_file_path) ⇒ Object



8
9
10
# File 'lib/dnsdeploy/base.rb', line 8

def self.update_records(records_file_path)
  self.new(records_file_path).update_records
end

Instance Method Details

#localObject



42
43
44
# File 'lib/dnsdeploy/base.rb', line 42

def local
  @local ||= Dnsdeploy::Local.new(@local_records_json)
end

#update_recordsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dnsdeploy/base.rb', line 19

def update_records
  local.domains.each do |domain|
    puts "[Processing] Domain #{domain.name}"

    # Delete records on DNSimple
    DNSimple::Record.all(domain).collect(&:destroy)

    # create records
    local.records(domain).each do |record|
      puts "[CREATE] #{record}".green
      begin
        DNSimple::Record.create(record.domain, record.name, record.record_type,
          record.content, { ttl: record.ttl, prio: record.prio })
      rescue DNSimple::RequestError => e
        puts "[ERROR] #{e} #{record}".red
        @exit = 1
      end
    end

    exit(@exit) if @exit
  end
end

#validateObject



12
13
14
15
16
17
# File 'lib/dnsdeploy/base.rb', line 12

def validate
  JSON.load(@local_records_json)
  puts "#{@records_file_path} is valid json".green
rescue => e
  puts "unable to parse #{@records_file_path}".red
end