Class: Iodine::Http::Response::Flash

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

Overview

Makes sure that the ‘flash` cookie-jar doesn’t have Symbols and Strings overlapping.

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

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



19
20
21
22
23
24
25
26
27
28
# File 'lib/iodine/http/response.rb', line 19

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
  elsif self.has_key? "magic_flash_#{key.to_s}".freeze.to_sym
    key = "magic_flash_#{key.to_s}".freeze.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).



10
11
12
13
14
15
16
17
# File 'lib/iodine/http/response.rb', line 10

def []= key, val
  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