Class: DoubleTrouble::CachedNonce
- Inherits:
-
Object
- Object
- DoubleTrouble::CachedNonce
- Defined in:
- lib/double_trouble/cached_nonce.rb
Instance Attribute Summary collapse
-
#nonce ⇒ Object
Returns the value of attribute nonce.
Class Method Summary collapse
Instance Method Summary collapse
- #cache_key ⇒ Object
-
#initialize(nonce) ⇒ CachedNonce
constructor
A new instance of CachedNonce.
- #save ⇒ Object
- #save! ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(nonce) ⇒ CachedNonce
Returns a new instance of CachedNonce.
16 17 18 |
# File 'lib/double_trouble/cached_nonce.rb', line 16 def initialize(nonce) self.nonce = nonce end |
Instance Attribute Details
#nonce ⇒ Object
Returns the value of attribute nonce.
6 7 8 |
# File 'lib/double_trouble/cached_nonce.rb', line 6 def nonce @nonce end |
Class Method Details
.store!(nonce) ⇒ Object
12 13 14 |
# File 'lib/double_trouble/cached_nonce.rb', line 12 def self.store!(nonce) new(nonce).save! end |
.valid?(nonce) ⇒ Boolean
8 9 10 |
# File 'lib/double_trouble/cached_nonce.rb', line 8 def self.valid?(nonce) new(nonce).valid? end |
Instance Method Details
#cache_key ⇒ Object
32 33 34 |
# File 'lib/double_trouble/cached_nonce.rb', line 32 def cache_key "double_trouble_cached_nonce.#{nonce}" end |
#save ⇒ Object
20 21 22 |
# File 'lib/double_trouble/cached_nonce.rb', line 20 def save valid? && ::Rails.cache.write(cache_key, true, :expires_in => self.class.expires_in) end |
#save! ⇒ Object
24 25 26 |
# File 'lib/double_trouble/cached_nonce.rb', line 24 def save! save || raise(InvalidNonce) end |
#valid? ⇒ Boolean
28 29 30 |
# File 'lib/double_trouble/cached_nonce.rb', line 28 def valid? nonce.present? && !::Rails.cache.exist?(cache_key, :expires_in => self.class.expires_in) end |