Class: CookieStore::HashStore
- Inherits:
-
CookieStore
- Object
- CookieStore
- CookieStore::HashStore
- Defined in:
- lib/cookie_store/hash_store.rb
Constant Summary
Constants inherited from CookieStore
MAX_COOKIES_PER_DOMAIN, MAX_COOKIES_TOTAL, MAX_COOKIE_LENGTH
Instance Method Summary collapse
- #add(cookie) ⇒ Object
- #cookies_for(request_uri) ⇒ Object
- #gc(close_session = false) ⇒ Object
-
#initialize ⇒ HashStore
constructor
A new instance of HashStore.
Methods inherited from CookieStore
#close_session, #cookie_header_for, #search_domains_for, #set_cookie
Constructor Details
#initialize ⇒ HashStore
Returns a new instance of HashStore.
3 4 5 |
# File 'lib/cookie_store/hash_store.rb', line 3 def initialize @domains = {} end |
Instance Method Details
#add(cookie) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/cookie_store/hash_store.rb', line 7 def add() #TODO: check for MAX_COOKIES_PER_DOMAIN && MAX_COOKIES_TOTAL, think remove the MAX_COOKIES_TOTAL tho @domains[.domain] ||= {} @domains[.domain][.path] ||= {} @domains[.domain][.path][.name] = end |
#cookies_for(request_uri) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cookie_store/hash_store.rb', line 14 def (request_uri) request_uri = URI.parse(request_uri) trigger_gc = false = [] search_domains_for(request_uri.host).each do |domain| next unless @domains[domain] @domains[domain].each do |path, | if request_uri.path.start_with?(path) .each do |name, | if .expired? trigger_gc = true elsif .port_match(request_uri.port) && (!.secure || (.secure && request_uri.scheme == 'https')) << end end end end end gc if trigger_gc end |
#gc(close_session = false) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cookie_store/hash_store.rb', line 40 def gc(close_session=false) @domains.delete_if do |domain, paths| paths.delete_if do |path, | .delete_if do |, | .expired? || (close_session && .session?) end .empty? end paths.empty? end end |