Class: Mach::Persistence::InMemoryStore
- Inherits:
-
DeltaAndNonceStore
- Object
- DeltaAndNonceStore
- Mach::Persistence::InMemoryStore
- Defined in:
- lib/mach/persistence/in_memory_store.rb
Instance Method Summary collapse
- #add_delta(credential_id, delta_value, expires_in) ⇒ Object
- #add_nonce(credential_id, nonce_value, expires_in) ⇒ Object
- #find_delta_by(credential_id) ⇒ Object
- #find_nonce_by(credential_id, nonce_value) ⇒ Object
-
#initialize(options = {}) ⇒ InMemoryStore
constructor
A new instance of InMemoryStore.
Methods inherited from DeltaAndNonceStore
Constructor Details
#initialize(options = {}) ⇒ InMemoryStore
Returns a new instance of InMemoryStore.
7 8 9 10 |
# File 'lib/mach/persistence/in_memory_store.rb', line 7 def initialize( = {}) @deltas = {} @nonces = {} end |
Instance Method Details
#add_delta(credential_id, delta_value, expires_in) ⇒ Object
23 24 25 26 27 |
# File 'lib/mach/persistence/in_memory_store.rb', line 23 def add_delta(credential_id, delta_value, expires_in) expires_at = Timestamp.now + expires_in @deltas[credential_id] = {:delta_value => delta_value, :expires_at => expires_at} @deltas[credential_id][:delta_value] end |
#add_nonce(credential_id, nonce_value, expires_in) ⇒ Object
41 42 43 44 45 |
# File 'lib/mach/persistence/in_memory_store.rb', line 41 def add_nonce(credential_id, nonce_value, expires_in) expires_at = Timestamp.now + expires_in @nonces[credential_id] ||= {} @nonces[credential_id][nonce_value] = expires_at end |
#find_delta_by(credential_id) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mach/persistence/in_memory_store.rb', line 12 def find_delta_by(credential_id) delta_hash = @deltas[credential_id] || {} now = Timestamp.now if delta_hash[:expires_at] && delta_hash[:expires_at] > now delta_hash[:delta_value] else @deltas[credential_id] = nil nil end end |
#find_nonce_by(credential_id, nonce_value) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mach/persistence/in_memory_store.rb', line 29 def find_nonce_by(credential_id, nonce_value) nonces_for_credential_id = @nonces[credential_id] || {} expires_at = nonces_for_credential_id[nonce_value] now = Timestamp.now if expires_at && expires_at > now nonce_value else nonces_for_credential_id[nonce_value] = nil nil end end |