Class: ForeverAlone::Validator
- Inherits:
-
Object
- Object
- ForeverAlone::Validator
- Defined in:
- lib/forever-alone/validator.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
- #ensure ⇒ Object
- #flush_locks ⇒ Object
-
#initialize(message, timeout = nil) ⇒ Validator
constructor
A new instance of Validator.
- #key ⇒ Object
- #remember ⇒ Object
- #unique? ⇒ Boolean
Constructor Details
#initialize(message, timeout = nil) ⇒ Validator
Returns a new instance of Validator.
6 7 8 9 |
# File 'lib/forever-alone/validator.rb', line 6 def initialize , timeout=nil = @timeout = timeout || ForeverAlone.configuration.timeout end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
4 5 6 |
# File 'lib/forever-alone/validator.rb', line 4 def end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
4 5 6 |
# File 'lib/forever-alone/validator.rb', line 4 def timeout @timeout end |
Instance Method Details
#ensure ⇒ Object
24 25 26 27 |
# File 'lib/forever-alone/validator.rb', line 24 def ensure raise ForeverAlone::MessageIsNotUnique, self.inspect unless unique? remember end |
#flush_locks ⇒ Object
15 16 17 18 |
# File 'lib/forever-alone/validator.rb', line 15 def flush_locks keys = ForeverAlone.redis.keys "#{ ForeverAlone.configuration.namespace }:*" ForeverAlone.redis.del keys if keys.any? end |
#key ⇒ Object
29 30 31 |
# File 'lib/forever-alone/validator.rb', line 29 def key @key ||= generate_key end |
#remember ⇒ Object
20 21 22 |
# File 'lib/forever-alone/validator.rb', line 20 def remember ForeverAlone.redis.setex key, timeout, 'foo' end |
#unique? ⇒ Boolean
11 12 13 |
# File 'lib/forever-alone/validator.rb', line 11 def unique? ForeverAlone.redis.get(key).nil? end |