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, opts = {}) ⇒ 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.
3 4 5 6 |
# File 'lib/grape/cookies.rb', line 3 def initialize @cookies = {} @send_cookies = {} end |
Instance Method Details
#[](name) ⇒ Object
21 22 23 |
# File 'lib/grape/cookies.rb', line 21 def [](name) @cookies[name.to_s] end |
#[]=(name, value) ⇒ Object
25 26 27 28 |
# File 'lib/grape/cookies.rb', line 25 def []=(name, value) @cookies[name.to_s] = value @send_cookies[name.to_s] = true end |
#delete(name, opts = {}) ⇒ Object
34 35 36 37 |
# File 'lib/grape/cookies.rb', line 34 def delete(name, opts = {}) = opts.merge(value: 'deleted', expires: Time.at(0)) self.[]=(name, ) end |
#each(&block) ⇒ Object
30 31 32 |
# File 'lib/grape/cookies.rb', line 30 def each(&block) @cookies.each(&block) end |
#read(request) ⇒ Object
8 9 10 11 12 |
# File 'lib/grape/cookies.rb', line 8 def read(request) request..each do |name, value| @cookies[name.to_s] = value end end |
#write(header) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/grape/cookies.rb', line 14 def write(header) @cookies.select { |key, value| @send_cookies[key] == true }.each do |name, value| = value.is_a?(Hash) ? value : { value: value } Rack::Utils. header, name, end end |