Class: VagrantAutoDNS::AutoDNSDB

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-autodns/autodnsdb.rb

Defined Under Namespace

Classes: Query

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dbObject (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_recordsObject



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_vmsObject



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_recordsObject



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