Class: SshGuard::Database
- Inherits:
-
Object
- Object
- SshGuard::Database
- Defined in:
- lib/ssh_guard/database.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
- #add_entry(entry = {}) ⇒ Object
-
#initialize ⇒ Database
constructor
A new instance of Database.
- #should_block?(ip_address) ⇒ Boolean
Constructor Details
#initialize ⇒ Database
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
#db ⇒ Object (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
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 |