Class: Dnsdeploy::Base
- Inherits:
-
Object
- Object
- Dnsdeploy::Base
- Defined in:
- lib/dnsdeploy/base.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(records_file) ⇒ Base
constructor
A new instance of Base.
- #local ⇒ Object
- #update_records ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(records_file) ⇒ Base
Returns a new instance of Base.
3 4 5 |
# File 'lib/dnsdeploy/base.rb', line 3 def initialize(records_file) @records_file = File.new(records_file) end |
Class Method Details
.update_records(records_file) ⇒ Object
7 8 9 |
# File 'lib/dnsdeploy/base.rb', line 7 def self.update_records(records_file) self.new(records_file).update_records end |
Instance Method Details
#local ⇒ Object
41 42 43 |
# File 'lib/dnsdeploy/base.rb', line 41 def local @local ||= Dnsdeploy::Local.new(@records_file) end |
#update_records ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dnsdeploy/base.rb', line 18 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 |
#validate ⇒ Object
11 12 13 14 15 16 |
# File 'lib/dnsdeploy/base.rb', line 11 def validate JSON.load(@records_file.read) puts "#{@records_file.path} is valid json".green rescue => e puts "unable to parse #{@records_file.path}".red end |