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.
5 6 7 8 |
# File 'lib/grape/cookies.rb', line 5 def initialize @cookies = {} @send_cookies = {} end |
Instance Method Details
#[](name) ⇒ Object
23 24 25 |
# File 'lib/grape/cookies.rb', line 23 def [](name) @cookies[name.to_s] end |
#[]=(name, value) ⇒ Object
27 28 29 30 |
# File 'lib/grape/cookies.rb', line 27 def []=(name, value) @cookies[name.to_s] = value @send_cookies[name.to_s] = true end |
#delete(name, **opts) ⇒ Object
36 37 38 39 |
# File 'lib/grape/cookies.rb', line 36 def delete(name, **opts) = opts.merge(value: 'deleted', expires: Time.at(0)) self.[]=(name, ) end |
#each(&block) ⇒ Object
32 33 34 |
# File 'lib/grape/cookies.rb', line 32 def each(&block) @cookies.each(&block) end |
#read(request) ⇒ Object
10 11 12 13 14 |
# File 'lib/grape/cookies.rb', line 10 def read(request) request..each do |name, value| @cookies[name.to_s] = value end end |
#write(header) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/grape/cookies.rb', line 16 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 |