Class: HTTP::CookieJar::AbstractSaver

Inherits:
Object
  • Object
show all
Defined in:
lib/http/cookie_jar/abstract_saver.rb

Direct Known Subclasses

CookiestxtSaver, YAMLSaver

Constant Summary collapse

@@class_map =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ AbstractSaver

Returns a new instance of AbstractSaver.



35
36
37
38
39
40
41
42
43
44
# File 'lib/http/cookie_jar/abstract_saver.rb', line 35

def initialize(options = nil)
  options ||= {}
  @logger  = options[:logger]
  @session = options[:session]
  # Initializes each instance variable of the same name as option
  # keyword.
  default_options.each_pair { |key, default|
    instance_variable_set("@#{key}", options.key?(key) ? options[key] : default)
  }
end

Class Method Details

.class_to_symbol(klass) ⇒ Object



25
26
27
# File 'lib/http/cookie_jar/abstract_saver.rb', line 25

def class_to_symbol(klass)
  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, KeyError is raised.



10
11
12
13
14
15
16
17
18
19
# File 'lib/http/cookie_jar/abstract_saver.rb', line 10

def implementation(symbol)
  @@class_map.fetch(symbol)
rescue KeyError
  begin
    require 'http/cookie_jar/%s_saver' % symbol
    @@class_map.fetch(symbol)
  rescue LoadError, KeyError => e
    raise KeyError, 'cookie saver unavailable: %s' % symbol.inspect
  end
end

.inherited(subclass) ⇒ Object



21
22
23
# File 'lib/http/cookie_jar/abstract_saver.rb', line 21

def inherited(subclass)
  @@class_map[class_to_symbol(subclass)] = subclass
end

Instance Method Details

#load(io, jar) ⇒ Object



50
51
52
# File 'lib/http/cookie_jar/abstract_saver.rb', line 50

def load(io, jar)
  raise
end

#save(io, jar) ⇒ Object



46
47
48
# File 'lib/http/cookie_jar/abstract_saver.rb', line 46

def save(io, jar)
  raise
end