Class: Anemone::CookieStore

Inherits:
Hash
  • Object
show all
Defined in:
lib/anemone/cookie_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(cookies = nil) ⇒ CookieStore

Returns a new instance of CookieStore.



13
14
15
16
17
# File 'lib/anemone/cookie_store.rb', line 13

def initialize(cookies = nil)
  @cookies = {}
  cookies.each { |name, value| @cookies[name] = WEBrick::Cookie.new(name, value) } if cookies
  super(@cookies)
end

Instance Method Details

#merge!(set_cookie_str) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/anemone/cookie_store.rb', line 19

def merge!(set_cookie_str)
  begin
    cookie_hash = WEBrick::Cookie.parse_set_cookies(set_cookie_str).inject({}) do |hash, cookie|
      hash[cookie.name] = cookie if !!cookie
      hash
    end
    @cookies.merge! cookie_hash
  rescue
  end
end

#to_sObject



30
31
32
# File 'lib/anemone/cookie_store.rb', line 30

def to_s
  @cookies.values.reject { |cookie| cookie.expired? }.map { |cookie| "#{cookie.name}=#{cookie.value}" }.join(';')
end