Class: VagrantAutoDNS::AutoDNSDB
- Inherits:
-
Object
- Object
- VagrantAutoDNS::AutoDNSDB
- Defined in:
- lib/vagrant-autodns/autodnsdb.rb
Defined Under Namespace
Classes: Query
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
- #delete_all_records ⇒ Object
- #delete_host(vagrant_id) ⇒ Object
- #delete_record(hostname) ⇒ Object
- #dependent_vms ⇒ Object
- #find_record(hostname) ⇒ Object
-
#initialize(db_file = 'autodns.db') ⇒ AutoDNSDB
constructor
A new instance of AutoDNSDB.
- #list_all_records ⇒ Object
- #update_record(hostname, ip, vagrant_id = nil) ⇒ Object
Constructor Details
#initialize(db_file = 'autodns.db') ⇒ AutoDNSDB
Returns a new instance of AutoDNSDB.
16 17 18 19 20 21 |
# File 'lib/vagrant-autodns/autodnsdb.rb', line 16 def initialize(db_file = 'autodns.db') FileUtils.mkdir_p(File.dirname(db_file)) @db = SQLite3::Database.new(db_file) @db.results_as_hash = true @db.execute(Query::CREATE_RECORDS_TABLE) end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
15 16 17 |
# File 'lib/vagrant-autodns/autodnsdb.rb', line 15 def db @db end |
Instance Method Details
#delete_all_records ⇒ Object
43 44 45 |
# File 'lib/vagrant-autodns/autodnsdb.rb', line 43 def delete_all_records @db.execute(Query::DELETE_ALL_RECORDS) end |
#delete_host(vagrant_id) ⇒ Object
35 36 37 |
# File 'lib/vagrant-autodns/autodnsdb.rb', line 35 def delete_host(vagrant_id) @db.execute(Query::DELETE_HOST, [vagrant_id]) end |
#delete_record(hostname) ⇒ Object
31 32 33 |
# File 'lib/vagrant-autodns/autodnsdb.rb', line 31 def delete_record(hostname) @db.execute(Query::DELETE_RECORD, [hostname]) end |
#dependent_vms ⇒ Object
47 48 49 |
# File 'lib/vagrant-autodns/autodnsdb.rb', line 47 def dependent_vms @db.execute(Query::LIST_DEPENDENT_VMS).map{|r| r['vagrant_id']} end |
#find_record(hostname) ⇒ Object
23 24 25 |
# File 'lib/vagrant-autodns/autodnsdb.rb', line 23 def find_record(hostname) @db.get_first_row(Query::FIND_RECORD, [hostname]) end |
#list_all_records ⇒ Object
39 40 41 |
# File 'lib/vagrant-autodns/autodnsdb.rb', line 39 def list_all_records @db.execute(Query::LIST_ALL_RECORDS) end |
#update_record(hostname, ip, vagrant_id = nil) ⇒ Object
27 28 29 |
# File 'lib/vagrant-autodns/autodnsdb.rb', line 27 def update_record(hostname, ip, vagrant_id = nil) @db.execute(Query::UPDATE_RECORD, [hostname, ip, vagrant_id, Time.now.to_i]) end |