Class: Grape::Cookies
- Inherits:
-
Object
- Object
- Grape::Cookies
- Defined in:
- lib/grape/cookies.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #delete(name) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize ⇒ Cookies
constructor
A new instance of Cookies.
- #read(request) ⇒ Object
- #write(header) ⇒ Object
Constructor Details
#initialize ⇒ Cookies
Returns a new instance of Cookies.
4 5 6 7 |
# File 'lib/grape/cookies.rb', line 4 def initialize @cookies = {} @send_cookies = {} end |
Instance Method Details
#[](name) ⇒ Object
24 25 26 |
# File 'lib/grape/cookies.rb', line 24 def [](name) @cookies[name] end |
#[]=(name, value) ⇒ Object
28 29 30 31 |
# File 'lib/grape/cookies.rb', line 28 def []=(name, value) @cookies[name.to_sym] = value @send_cookies[name.to_sym] = true end |
#delete(name) ⇒ Object
37 38 39 |
# File 'lib/grape/cookies.rb', line 37 def delete(name) self.[]=(name, { :value => 'deleted', :expires => Time.at(0) }) end |
#each(&block) ⇒ Object
33 34 35 |
# File 'lib/grape/cookies.rb', line 33 def each(&block) @cookies.each(&block) end |
#read(request) ⇒ Object
9 10 11 12 13 |
# File 'lib/grape/cookies.rb', line 9 def read(request) request..each do |name, value| @cookies[name.to_sym] = value end end |
#write(header) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/grape/cookies.rb', line 15 def write(header) @cookies.select { |key, value| @send_cookies[key.to_sym] == true }.each { |name, value| Rack::Utils.( header, name, value.instance_of?(Hash) ? value : { :value => value }) } end |