Class: Iodine::Http::Request::Cookies

Inherits:
Hash
  • Object
show all
Defined in:
lib/iodine/http/request.rb

Overview

Sets magic cookies - NOT part of the API.

magic cookies keep track of both incoming and outgoing cookies, setting the response’s cookies as well as the combined cookie respetory (held by the request object).

use only the []= for magic cookies. merge and update might not set the response cookies.

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

overrides th [] method to allow Symbols and Strings to mix and match



35
36
37
38
39
40
41
42
# File 'lib/iodine/http/request.rb', line 35

def [] key
  if key.is_a?(Symbol) && self.has_key?( key.to_s)
    key = key.to_s
  elsif self.has_key?( key.to_s.to_sym)
    key = key.to_s.to_sym
  end
  super
end

#[]=(key, val) ⇒ Object

overrides the []= method to set the cookie for the response (by encoding it and preparing it to be sent), as well as to save the cookie in the combined cookie jar (unencoded and available).



24
25
26
27
28
29
30
31
32
33
# File 'lib/iodine/http/request.rb', line 24

def []= key, val
  return super unless instance_variable_defined?(:@response) && @response
  if key.is_a?(Symbol) && self.has_key?( key.to_s)
    key = key.to_s
  elsif self.has_key?( key.to_s.to_sym)
    key = key.to_s.to_sym
  end
  @response.set_cookie key, (val.nil? ? nil : val)
  super
end

#set_response(response) ⇒ Object

sets the Magic Cookie’s controller object (which holds the response object and it’s ‘set_cookie` method).



20
21
22
# File 'lib/iodine/http/request.rb', line 20

def set_response response
  @response = response
end