Class: SSH::Manager::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh/manager/db.rb

Constant Summary collapse

DATABASE =

TODO make group a n:m relation to extra table

Sequel.sqlite(@database_file)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDatabase

Returns a new instance of Database.



39
40
41
# File 'lib/ssh/manager/db.rb', line 39

def initialize
  @connections = DATABASE[:connection]
end

Instance Attribute Details

#connectionsObject

Returns the value of attribute connections.



37
38
39
# File 'lib/ssh/manager/db.rb', line 37

def connections
  @connections
end

Instance Method Details

#add_new_connection(connection) ⇒ Object



51
52
53
# File 'lib/ssh/manager/db.rb', line 51

def add_new_connection(connection)
  @connections.insert(connection)
end

#delete_connection(id) ⇒ Object



55
56
57
# File 'lib/ssh/manager/db.rb', line 55

def delete_connection(id)
  @connections.where(:id => id).delete
end

#get_connection_by_id(id) ⇒ Object



43
44
45
# File 'lib/ssh/manager/db.rb', line 43

def get_connection_by_id(id)
  @connections[:id => id].to_hash
end

#get_connection_dataObject



47
48
49
# File 'lib/ssh/manager/db.rb', line 47

def get_connection_data
  @connections.all
end

#search_for(term) ⇒ Object



63
64
65
66
# File 'lib/ssh/manager/db.rb', line 63

def search_for(term)
  # check online: search for 'contains' not for complete matching
  return  @connections.where(:ip => term),  @connections.where(:user => term), @connections.where(:hostname => term), @connections.where(:port => term), @connections.where(:note => term), @connections.where(:group => term), @connections.where(:options => term)
end

#update_connection(connection) ⇒ Object



59
60
61
# File 'lib/ssh/manager/db.rb', line 59

def update_connection(connection)
  @connections.where(:id => connection[:id]).update(connection)
end