Class: HTTP::CookieJar::AbstractSaver
- Inherits:
-
Object
- Object
- HTTP::CookieJar::AbstractSaver
- Defined in:
- lib/http/cookie_jar/abstract_saver.rb
Overview
An abstract superclass for all saver classes.
Direct Known Subclasses
Constant Summary collapse
- @@class_map =
{}
Class Method Summary collapse
-
.class_to_symbol(klass) ⇒ Object
:nodoc:.
-
.implementation(symbol) ⇒ Object
Gets an implementation class by the name, optionally trying to load “http/cookie_jar/*_saver” if not found.
-
.inherited(subclass) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(options = nil) ⇒ AbstractSaver
constructor
:call-seq: new(**options).
-
#load(io, jar) ⇒ Object
Implements HTTP::CookieJar#load().
-
#save(io, jar) ⇒ Object
Implements HTTP::CookieJar#save().
Constructor Details
#initialize(options = nil) ⇒ AbstractSaver
:call-seq:
new(**)
Called by the constructor of each subclass using super().
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/http/cookie_jar/abstract_saver.rb', line 41 def initialize( = nil) ||= {} @logger = [:logger] @session = [:session] # 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
.class_to_symbol(klass) ⇒ Object
:nodoc:
26 27 28 |
# File 'lib/http/cookie_jar/abstract_saver.rb', line 26 def class_to_symbol(klass) # :nodoc: klass.name[/[^:]+?(?=Saver$|$)/].downcase.to_sym end |
.implementation(symbol) ⇒ Object
Gets an implementation class by the name, optionally trying to load “http/cookie_jar/*_saver” if not found. If loading fails, IndexError is raised.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/http/cookie_jar/abstract_saver.rb', line 11 def implementation(symbol) @@class_map.fetch(symbol) rescue IndexError begin require 'http/cookie_jar/%s_saver' % symbol @@class_map.fetch(symbol) rescue LoadError, IndexError raise IndexError, 'cookie saver unavailable: %s' % symbol.inspect end end |
.inherited(subclass) ⇒ Object
:nodoc:
22 23 24 |
# File 'lib/http/cookie_jar/abstract_saver.rb', line 22 def inherited(subclass) # :nodoc: @@class_map[class_to_symbol(subclass)] = subclass end |
Instance Method Details
#load(io, jar) ⇒ Object
Implements HTTP::CookieJar#load().
This is an abstract method that each subclass must override.
62 63 64 |
# File 'lib/http/cookie_jar/abstract_saver.rb', line 62 def load(io, jar) # self end |
#save(io, jar) ⇒ Object
Implements HTTP::CookieJar#save().
This is an abstract method that each subclass must override.
55 56 57 |
# File 'lib/http/cookie_jar/abstract_saver.rb', line 55 def save(io, jar) # self end |