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
see https://github.com/rack/rack/blob/main/lib/rack/utils.rb#L338-L340 rubocop:disable Layout/SpaceBeforeBrackets.
- #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
see https://github.com/rack/rack/blob/main/lib/rack/utils.rb#L338-L340 rubocop:disable Layout/SpaceBeforeBrackets
38 39 40 41 |
# File 'lib/grape/cookies.rb', line 38 def delete(name, **opts) = opts.merge(max_age: '0', value: '', 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 |