Class: Merb::Cookies
- Inherits:
-
Mash
- Object
- Mash
- Merb::Cookies
- Defined in:
- merb-core/lib/merb-core/dispatch/cookies.rb
Instance Method Summary (collapse)
-
- (Object) []=(key, value)
Implicit assignment of cookie key and value.
-
- (Object) delete(name, options = {})
Removes the cookie on the client machine by setting the value to an empty string and setting its expiration date into the past.
-
- (Hash) extract_headers(controller_defaults = {})
private
Generate any necessary headers.
-
- (Cookies) initialize(constructor = {})
constructor
private
A new instance of Cookies.
-
- (Object) set_cookie(name, value, options = {})
private
Explicit assignment of cookie key, value and options.
Constructor Details
- (Cookies) initialize(constructor = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
A new instance of Cookies
6 7 8 9 10 |
# File 'merb-core/lib/merb-core/dispatch/cookies.rb', line 6 def initialize(constructor = {}) @_options_lookup = Mash.new @_cookie_defaults = { "domain" => Merb::Controller., "path" => '/' } super constructor end |
Instance Method Details
- (Object) []=(key, value)
Implicit assignment of cookie key and value.
By using this method, a cookie key is marked for being included in the Set-Cookie response header.
21 22 23 24 |
# File 'merb-core/lib/merb-core/dispatch/cookies.rb', line 21 def []=(key, value) @_options_lookup[key] ||= {} super end |
- (Object) delete(name, options = {})
Removes the cookie on the client machine by setting the value to an empty string and setting its expiration date into the past.
57 58 59 |
# File 'merb-core/lib/merb-core/dispatch/cookies.rb', line 57 def delete(name, = {}) (name, "", .merge("expires" => Time.at(0))) end |
- (Hash) extract_headers(controller_defaults = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generate any necessary headers.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'merb-core/lib/merb-core/dispatch/cookies.rb', line 67 def extract_headers(controller_defaults = {}) defaults = @_cookie_defaults.merge(controller_defaults) = [] self.each do |name, value| # Only set cookies that marked for inclusion in the response header. next unless @_options_lookup[name] = defaults.merge(@_options_lookup[name]) if (expiry = ["expires"]).respond_to?(:gmtime) ["expires"] = expiry.gmtime.strftime(Merb::Const::COOKIE_EXPIRATION_FORMAT) end secure = .delete("secure") http_only = .delete("http_only") kookie = "#{name}=#{Merb::Parse.escape(value)}; " # WebKit in particular doens't like empty cookie options - skip them. .each { |k, v| kookie << "#{k}=#{v}; " unless v.blank? } kookie << 'secure; ' if secure kookie << 'HttpOnly; ' if http_only << kookie.rstrip end .empty? ? {} : { 'Set-Cookie' => .join(Merb::Const::NEWLINE) } end |
- (Object) set_cookie(name, value, options = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Explicit assignment of cookie key, value and options
By using this method, a cookie key is marked for being included in the Set-Cookie response header.
45 46 47 48 |
# File 'merb-core/lib/merb-core/dispatch/cookies.rb', line 45 def (name, value, = {}) @_options_lookup[name] = self[name] = value end |