Module: Rack::Client::CookieJar::Options

Included in:
Context
Defined in:
lib/rack/client/middleware/cookie_jar/options.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.option_accessor(key) ⇒ Object



5
6
7
8
9
10
# File 'lib/rack/client/middleware/cookie_jar/options.rb', line 5

def self.option_accessor(key)
  name = option_name(key)
  define_method(key) { || options[name] }
  define_method("#{key}=") { |value| options[name] = value }
  define_method("#{key}?") { || !! options[name] }
end

.option_name(key) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/rack/client/middleware/cookie_jar/options.rb', line 20

def option_name(key)
  case key
  when Symbol ; "rack-client-cookiejar.#{key}"
  when String ; key
  else raise ArgumentError
  end
end

Instance Method Details

#initialize_options(options = {}) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/rack/client/middleware/cookie_jar/options.rb', line 33

def initialize_options(options={})
  @default_options = {
    'rack-client-cookiejar.storage'     => Storage.new,
    'rack-client-cookiejar.cookiestore' => 'heap:/',
  }
  self.options = options
end

#optionsObject



12
13
14
# File 'lib/rack/client/middleware/cookie_jar/options.rb', line 12

def options
  @default_options.merge(@options)
end

#options=(hash = {}) ⇒ Object



16
17
18
# File 'lib/rack/client/middleware/cookie_jar/options.rb', line 16

def options=(hash = {})
  @options = hash.each { |key,value| write_option(key, value) }
end