Class: SshGuard::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh_guard/database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDatabase

Returns a new instance of Database.



7
8
9
10
11
12
13
14
# File 'lib/ssh_guard/database.rb', line 7

def initialize()
  @db = Sequel.sqlite
  @db.create_table :entries do 
    primary_key :id
    String :ip_address
    Time :timestamp
  end
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



5
6
7
# File 'lib/ssh_guard/database.rb', line 5

def db
  @db
end

Instance Method Details

#add_entry(entry = {}) ⇒ Object



16
17
18
# File 'lib/ssh_guard/database.rb', line 16

def add_entry(entry={})
  db[:entries].insert(entry) unless entry.empty?
end

#should_block?(ip_address) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/ssh_guard/database.rb', line 20

def should_block?(ip_address)
  count = @db[:entries].where({:ip_address => ip_address}).count 
  count > 10
end