Class: FailToBan::Strategies::BackoffStrategy
- Inherits:
-
Object
- Object
- FailToBan::Strategies::BackoffStrategy
- Defined in:
- lib/fail_to_ban/strategies/backoff_strategy.rb
Instance Method Summary collapse
- #attempt ⇒ Object
- #blocked? ⇒ Boolean
-
#initialize(key:, storage:, config: {}) ⇒ BackoffStrategy
constructor
A new instance of BackoffStrategy.
- #reset ⇒ Object
- #unlock_at ⇒ Object
Constructor Details
#initialize(key:, storage:, config: {}) ⇒ BackoffStrategy
16 17 18 19 20 |
# File 'lib/fail_to_ban/strategies/backoff_strategy.rb', line 16 def initialize(key:, storage:, config: {}) @storage = storage @config = default_config.merge(config) @id = "#{HEADER}:#{key}" end |
Instance Method Details
#attempt ⇒ Object
22 23 24 25 26 |
# File 'lib/fail_to_ban/strategies/backoff_strategy.rb', line 22 def attempt return :blocked if blocked? increment_failed_attempts :ok end |
#blocked? ⇒ Boolean
28 29 30 |
# File 'lib/fail_to_ban/strategies/backoff_strategy.rb', line 28 def blocked? retry_count >= @config[:permitted_attempts] && Time.now.utc.to_i < unlock_at end |
#reset ⇒ Object
32 33 34 |
# File 'lib/fail_to_ban/strategies/backoff_strategy.rb', line 32 def reset @storage.del(@id) end |
#unlock_at ⇒ Object
36 37 38 |
# File 'lib/fail_to_ban/strategies/backoff_strategy.rb', line 36 def unlock_at @storage.hget(@id, 'unlock_at').to_i end |