C0 code coverage information
Generated on Fri Jul 11 15:55:34 -0700 2008 with rcov 0.7.0
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 require 'openid/store/interface'
2 module OpenID
3 module Store
4 # An in-memory implementation of Store. This class is mainly used
5 # for testing, though it may be useful for long-running single
6 # process apps. Note that this store is NOT thread-safe.
7 #
8 # You should probably be looking at OpenID::Store::Filesystem
9 class Memory < Interface
10
11 def initialize
12 @associations = {}
13 @associations.default = {}
14 @nonces = {}
15 end
16
17 def store_association(server_url, assoc)
18 assocs = @associations[server_url]
19 @associations[server_url] = assocs.merge({assoc.handle => deepcopy(assoc)})
20 end
21
22 def get_association(server_url, handle=nil)
23 assocs = @associations[server_url]
24 assoc = nil
25 if handle
26 assoc = assocs[handle]
27 else
28 assoc = assocs.values.sort{|a,b| a.issued <=> b.issued}[-1]
29 end
30
31 return assoc
32 end
33
34 def remove_association(server_url, handle)
35 assocs = @associations[server_url]
36 if assocs.delete(handle)
37 return true
38 else
39 return false
40 end
41 end
42
43 def use_nonce(server_url, timestamp, salt)
44 return false if (timestamp - Time.now.to_i).abs > Nonce.skew
45 nonce = [server_url, timestamp, salt].join('')
46 return false if @nonces[nonce]
47 @nonces[nonce] = timestamp
48 return true
49 end
50
51 def cleanup_associations
52 count = 0
53 @associations.each{|server_url, assocs|
54 assocs.each{|handle, assoc|
55 if assoc.expires_in == 0
56 assocs.delete(handle)
57 count += 1
58 end
59 }
60 }
61 return count
62 end
63
64 def cleanup_nonces
65 count = 0
66 now = Time.now.to_i
67 @nonces.each{|nonce, timestamp|
68 if (timestamp - now).abs > Nonce.skew
69 @nonces.delete(nonce)
70 count += 1
71 end
72 }
73 return count
74 end
75
76 protected
77
78 def deepcopy(o)
79 Marshal.load(Marshal.dump(o))
80 end
81
82 end
83 end
84 end
Generated using the rcov code coverage analysis tool for Ruby version 0.7.0.