Class: Lookout::Rack::Cookies

Inherits:
Object
  • Object
show all
Defined in:
lib/lookout-rack-1.0/cookies.rb

Instance Method Summary collapse

Constructor Details

#initialize(default_host = Lookout::Rack::DefaultHost) ⇒ Cookies

Returns a new instance of Cookies.



4
5
6
7
# File 'lib/lookout-rack-1.0/cookies.rb', line 4

def initialize(default_host = Lookout::Rack::DefaultHost)
  @default_host = default_host
  @cookies = {}
end

Instance Method Details

#for(uri) ⇒ Object



17
18
19
20
# File 'lib/lookout-rack-1.0/cookies.rb', line 17

def for(uri)
  @cookies.values.select{ |c| c.matches? uri }.sort.
    reduce({}){ |h, c| h[c.name] = c; h }.values.join(';')
end

#merge!(headers, uri = nil) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/lookout-rack-1.0/cookies.rb', line 9

def merge!(headers, uri = nil)
  headers.split("\n").reject{ |c| c.empty? }.each do |header|
    cookie = Lookout::Rack::Cookie.new(header, uri, @default_host)
    @cookies[cookie] = cookie if cookie.valid? uri
  end
  self
end