Class: SSH::Manager::Database

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

Constant Summary collapse

DATABASE =
Sequel.connect("sqlite://#{@path}/sshm.db")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDatabase

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

#connectionsObject

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_dataObject



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