Class: ThrottleAdapter
- Inherits:
-
Object
- Object
- ThrottleAdapter
- Defined in:
- lib/sequel-rack_throttle/ThrottleAdapter.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
Returns the value of attribute db.
-
#table ⇒ Object
Returns the value of attribute table.
Instance Method Summary collapse
- #dataset ⇒ Object
- #get(key) ⇒ Object
-
#initialize(sequel_db, sequel_table = 'throttle_cache') ⇒ ThrottleAdapter
constructor
A new instance of ThrottleAdapter.
- #set(key, value) ⇒ Object
Constructor Details
#initialize(sequel_db, sequel_table = 'throttle_cache') ⇒ ThrottleAdapter
Returns a new instance of ThrottleAdapter.
4 5 6 7 8 9 10 11 12 |
# File 'lib/sequel-rack_throttle/ThrottleAdapter.rb', line 4 def initialize(sequel_db, sequel_table = 'throttle_cache') @db = sequel_db @table = sequel_table create_table? @table.to_sym do String :key, primary_key: true Float :value, default: 0 end end |
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
2 3 4 |
# File 'lib/sequel-rack_throttle/ThrottleAdapter.rb', line 2 def db @db end |
#table ⇒ Object
Returns the value of attribute table.
2 3 4 |
# File 'lib/sequel-rack_throttle/ThrottleAdapter.rb', line 2 def table @table end |
Instance Method Details
#dataset ⇒ Object
14 15 16 |
# File 'lib/sequel-rack_throttle/ThrottleAdapter.rb', line 14 def dataset @db[@table.to_sym] end |
#get(key) ⇒ Object
18 19 20 |
# File 'lib/sequel-rack_throttle/ThrottleAdapter.rb', line 18 def get(key) (dataset.filter(key: key).first[:value]) end |
#set(key, value) ⇒ Object
22 23 24 |
# File 'lib/sequel-rack_throttle/ThrottleAdapter.rb', line 22 def set(key, value) unless dataset.where(key: key).update(value: value) == 1 then dataset.insert(key: key, value: value) end end |