Class: HTTP::CookieJar::AbstractStore

Inherits:
Object
  • Object
show all
Includes:
Enumerable, MonitorMixin
Defined in:
lib/http/cookie_jar/abstract_store.rb

Overview

An abstract superclass for all store classes.

Direct Known Subclasses

HashStore, MozillaStore

Constant Summary collapse

@@class_map =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ AbstractStore

:call-seq:

new(**options)

Called by the constructor of each subclass using super().


44
45
46
47
48
49
50
51
52
53
# File 'lib/http/cookie_jar/abstract_store.rb', line 44

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

Class Method Details

.class_to_symbol(klass) ⇒ Object

:nodoc:


29
30
31
# File 'lib/http/cookie_jar/abstract_store.rb', line 29

def class_to_symbol(klass) # :nodoc:
  klass.name[/[^:]+?(?=Store$|$)/].downcase.to_sym
end

.implementation(symbol) ⇒ Object

Gets an implementation class by the name, optionally trying to load “http/cookie_jar/*_store” if not found. If loading fails, IndexError is raised.


14
15
16
17
18
19
20
21
22
23
# File 'lib/http/cookie_jar/abstract_store.rb', line 14

def implementation(symbol)
  @@class_map.fetch(symbol)
rescue IndexError
  begin
    require 'http/cookie_jar/%s_store' % symbol
    @@class_map.fetch(symbol)
  rescue LoadError, IndexError
    raise IndexError, 'cookie store unavailable: %s' % symbol.inspect
  end
end

.inherited(subclass) ⇒ Object

:nodoc:


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

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

Instance Method Details

#add(cookie) ⇒ Object

Implements HTTP::CookieJar#add().

This is an abstract method that each subclass must override.


63
64
65
# File 'lib/http/cookie_jar/abstract_store.rb', line 63

def add(cookie)
  # self
end

#cleanup(session = false) ⇒ Object

Implements HTTP::CookieJar#cleanup().

This is an abstract method that each subclass must override.


113
114
115
116
117
118
119
120
121
122
123
# File 'lib/http/cookie_jar/abstract_store.rb', line 113

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

#clearObject

Implements HTTP::CookieJar#clear().

This is an abstract method that each subclass must override.


106
107
108
# File 'lib/http/cookie_jar/abstract_store.rb', line 106

def clear
  # self
end

#delete(cookie) ⇒ Object

Implements HTTP::CookieJar#delete().

This is an abstract method that each subclass must override.


70
71
72
# File 'lib/http/cookie_jar/abstract_store.rb', line 70

def delete(cookie)
  # 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.


85
86
87
88
89
90
91
92
93
94
# File 'lib/http/cookie_jar/abstract_store.rb', line 85

def each(uri = nil, &block) # :yield: cookie
  # if uri
  #   ...
  # else
  #   synchronize {
  #     ...
  #   }
  # end
  # self
end

#empty?Boolean

Implements HTTP::CookieJar#empty?().

Returns:

  • (Boolean)

98
99
100
101
# File 'lib/http/cookie_jar/abstract_store.rb', line 98

def empty?
  each { return false }
  true
end

#initialize_copy(other) ⇒ Object

This is an abstract method that each subclass must override.


56
57
58
# File 'lib/http/cookie_jar/abstract_store.rb', line 56

def initialize_copy(other)
  # self
end