Class: OpenID::Store::Memory
- Defined in:
- lib/openid/store/memory.rb
Overview
An in-memory implementation of Store. This class is mainly used for testing, though it may be useful for long-running single process apps. Note that this store is NOT thread-safe.
You should probably be looking at OpenID::Store::Filesystem
Instance Method Summary collapse
- #cleanup_associations ⇒ Object
- #cleanup_nonces ⇒ Object
- #get_association(server_url, handle = nil) ⇒ Object
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #remove_association(server_url, handle) ⇒ Object
- #store_association(server_url, assoc) ⇒ Object
- #use_nonce(server_url, timestamp, salt) ⇒ Object
Methods inherited from Interface
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
11 12 13 14 15 |
# File 'lib/openid/store/memory.rb', line 11 def initialize @associations = {} @associations.default = {} @nonces = {} end |
Instance Method Details
#cleanup_associations ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/openid/store/memory.rb', line 51 def cleanup_associations count = 0 @associations.each{|server_url, assocs| assocs.each{|handle, assoc| if assoc.expires_in == 0 assocs.delete(handle) count += 1 end } } return count end |
#cleanup_nonces ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/openid/store/memory.rb', line 64 def cleanup_nonces count = 0 now = Time.now.to_i @nonces.each{|nonce, | if ( - now).abs > Nonce.skew @nonces.delete(nonce) count += 1 end } return count end |
#get_association(server_url, handle = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/openid/store/memory.rb', line 22 def get_association(server_url, handle=nil) assocs = @associations[server_url] assoc = nil if handle assoc = assocs[handle] else assoc = assocs.values.sort{|a,b| a.issued <=> b.issued}[-1] end return assoc end |
#remove_association(server_url, handle) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/openid/store/memory.rb', line 34 def remove_association(server_url, handle) assocs = @associations[server_url] if assocs.delete(handle) return true else return false end end |
#store_association(server_url, assoc) ⇒ Object
17 18 19 20 |
# File 'lib/openid/store/memory.rb', line 17 def store_association(server_url, assoc) assocs = @associations[server_url] @associations[server_url] = assocs.merge({assoc.handle => deepcopy(assoc)}) end |
#use_nonce(server_url, timestamp, salt) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/openid/store/memory.rb', line 43 def use_nonce(server_url, , salt) return false if ( - Time.now.to_i).abs > Nonce.skew nonce = [server_url, , salt].join('') return false if @nonces[nonce] @nonces[nonce] = return true end |