Class: HTTP::CookieJar::AbstractStore
- Inherits:
-
Object
- Object
- HTTP::CookieJar::AbstractStore
- Includes:
- Enumerable, MonitorMixin
- Defined in:
- lib/http/cookie_jar/abstract_store.rb
Overview
An abstract superclass for all store classes.
Direct Known Subclasses
Class Method Summary collapse
-
.implementation(symbol) ⇒ Object
Gets an implementation class by the name.
Instance Method Summary collapse
-
#add(cookie) ⇒ Object
Implements HTTP::CookieJar#add().
-
#cleanup(session = false) ⇒ Object
Implements HTTP::CookieJar#cleanup().
-
#clear ⇒ Object
Implements HTTP::CookieJar#clear().
-
#delete(cookie) ⇒ Object
Implements HTTP::CookieJar#delete().
-
#each(uri = nil, &block) ⇒ Object
Iterates over all cookies that are not expired.
-
#empty? ⇒ Boolean
Implements HTTP::CookieJar#empty?().
-
#initialize(options = nil) ⇒ AbstractStore
constructor
:call-seq: new(**options).
-
#initialize_copy(other) ⇒ Object
This is an abstract method that each subclass must override.
Constructor Details
#initialize(options = nil) ⇒ AbstractStore
:call-seq:
new(**)
Called by the constructor of each subclass using super().
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/http/cookie_jar/abstract_store.rb', line 33 def initialize( = nil) super() # MonitorMixin ||= {} @logger = [:logger] # Initializes each instance variable of the same name as option # keyword. .each_pair { |key, default| instance_variable_set("@#{key}", .fetch(key, default)) } end |
Class Method Details
.implementation(symbol) ⇒ Object
Gets an implementation class by the name.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/http/cookie_jar/abstract_store.rb', line 11 def implementation(symbol) case symbol when :hash HTTP::CookieJar::HashStore when :mozilla HTTP::CookieJar::MozillaStore else raise IndexError, 'cookie store unavailable: %s' % symbol.inspect end end |
Instance Method Details
#add(cookie) ⇒ Object
Implements HTTP::CookieJar#add().
This is an abstract method that each subclass must override.
52 53 54 |
# File 'lib/http/cookie_jar/abstract_store.rb', line 52 def add() # self end |
#cleanup(session = false) ⇒ Object
Implements HTTP::CookieJar#cleanup().
This is an abstract method that each subclass must override.
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/http/cookie_jar/abstract_store.rb', line 102 def cleanup(session = false) # if session # select { |cookie| cookie.session? || cookie.expired? } # else # select(&:expired?) # end.each { |cookie| # delete(cookie) # } # # subclasses can optionally remove over-the-limit cookies. # self end |
#clear ⇒ Object
Implements HTTP::CookieJar#clear().
This is an abstract method that each subclass must override.
95 96 97 |
# File 'lib/http/cookie_jar/abstract_store.rb', line 95 def clear # self end |
#delete(cookie) ⇒ Object
Implements HTTP::CookieJar#delete().
This is an abstract method that each subclass must override.
59 60 61 |
# File 'lib/http/cookie_jar/abstract_store.rb', line 59 def delete() # self end |
#each(uri = nil, &block) ⇒ Object
Iterates over all cookies that are not expired.
An optional argument uri specifies a URI object indicating the destination of the cookies being selected. Every cookie yielded should be good to send to the given URI, i.e. cookie.valid_for_uri?(uri) evaluates to true.
If (and only if) the uri option is given, last access time of each cookie is updated to the current time.
This is an abstract method that each subclass must override.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/http/cookie_jar/abstract_store.rb', line 74 def each(uri = nil, &block) # :yield: cookie # if uri # ... # else # synchronize { # ... # } # end # self end |
#empty? ⇒ Boolean
Implements HTTP::CookieJar#empty?().
87 88 89 90 |
# File 'lib/http/cookie_jar/abstract_store.rb', line 87 def empty? each { return false } true end |
#initialize_copy(other) ⇒ Object
This is an abstract method that each subclass must override.
45 46 47 |
# File 'lib/http/cookie_jar/abstract_store.rb', line 45 def initialize_copy(other) # self end |