Class: FastSubmissionProtection::SubmissionTimer
- Inherits:
-
Object
- Object
- FastSubmissionProtection::SubmissionTimer
- Defined in:
- lib/fast_submission_protection/submission_timer.rb
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(storage, key, delay = nil, clock = nil) ⇒ SubmissionTimer
constructor
A new instance of SubmissionTimer.
- #restart ⇒ Object
- #start ⇒ Object
- #too_fast? ⇒ Boolean
Constructor Details
#initialize(storage, key, delay = nil, clock = nil) ⇒ SubmissionTimer
Returns a new instance of SubmissionTimer.
7 8 9 10 11 |
# File 'lib/fast_submission_protection/submission_timer.rb', line 7 def initialize storage, key, delay = nil, clock = nil @storage, @key = storage, key @delay = delay || self.class.delay @clock = clock || self.class.clock end |
Instance Method Details
#clear ⇒ Object
26 27 28 |
# File 'lib/fast_submission_protection/submission_timer.rb', line 26 def clear @storage.delete @key end |
#restart ⇒ Object
22 23 24 |
# File 'lib/fast_submission_protection/submission_timer.rb', line 22 def restart @storage[@key] = @clock.now end |
#start ⇒ Object
18 19 20 |
# File 'lib/fast_submission_protection/submission_timer.rb', line 18 def start @storage[@key] ||= @clock.now end |
#too_fast? ⇒ Boolean
13 14 15 16 |
# File 'lib/fast_submission_protection/submission_timer.rb', line 13 def too_fast? started = @storage[@key] !started || (started + @delay > @clock.now) end |