Class: SSH::Manager::Database
- Inherits:
-
Object
- Object
- SSH::Manager::Database
- Defined in:
- lib/ssh/manager/db.rb
Constant Summary collapse
- DATABASE =
Sequel.connect("sqlite://#{@path}/sshm.db")
Instance Attribute Summary collapse
-
#connections ⇒ Object
Returns the value of attribute connections.
Instance Method Summary collapse
- #add_new_connection(ip, user = 'root', hostname = '', port = 22, note = '', created_at, option, count, group, last_time) ⇒ Object
- #delete_connection(ip) ⇒ Object
- #get_connection_data ⇒ Object
-
#initialize ⇒ Database
constructor
A new instance of Database.
- #search_for(term) ⇒ Object
- #update_connection(ip, user, hostname, port, note) ⇒ Object
Constructor Details
#initialize ⇒ Database
Returns a new instance of Database.
16 17 18 |
# File 'lib/ssh/manager/db.rb', line 16 def initialize @connections= DATABASE.from(:connection) end |
Instance Attribute Details
#connections ⇒ Object
Returns the value of attribute connections.
14 15 16 |
# File 'lib/ssh/manager/db.rb', line 14 def connections @connections end |
Instance Method Details
#add_new_connection(ip, user = 'root', hostname = '', port = 22, note = '', created_at, option, count, group, last_time) ⇒ Object
24 25 26 |
# File 'lib/ssh/manager/db.rb', line 24 def add_new_connection(ip, user='root', hostname='', port=22, note='', created_at, option, count, group, last_time) @connections.insert(:ip => ip, :user => user, :hostname => hostname, :port => port, :note => note, :created_at => created_at, :options => option, :group => group, :count => count, :last_time => last_time) end |
#delete_connection(ip) ⇒ Object
28 29 30 31 |
# File 'lib/ssh/manager/db.rb', line 28 def delete_connection(ip) # add && :user => user to ensure deletion @connections.where(:ip => ip).delete end |
#get_connection_data ⇒ Object
20 21 22 |
# File 'lib/ssh/manager/db.rb', line 20 def get_connection_data @connections.map([:ip, :user, :note, :group]) end |
#search_for(term) ⇒ Object
37 38 39 40 |
# File 'lib/ssh/manager/db.rb', line 37 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(ip, user, hostname, port, note) ⇒ Object
33 34 35 |
# File 'lib/ssh/manager/db.rb', line 33 def update_connection(ip, user, hostname, port, note) @connections.where(:ip => ip).update(:user => user, :hostname => hostname, :port => port, :note => note) end |