File: cookie.rb

package info (click to toggle)
ruby-moneta 1.6.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,776 kB
  • sloc: ruby: 13,201; sh: 178; makefile: 7
file content (42 lines) | stat: -rw-r--r-- 967 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Moneta
  module Adapters
    # Cookie backend used by the middleware {Rack::MonetaCookies}
    # @api public
    class Cookie < Memory
      attr_reader :cookies

      def initialize(options = {})
        super
        @options, @cookies = options, {}
      end

      # (see Proxy#store)
      def store(key, value, options = {})
        cookie = @options.merge(options)
        cookie[:value] = value
        cookie[:expires] += Time.now.to_i if cookie[:expires]
        @cookies[key] = cookie
        super
      end

      # (see Proxy#delete)
      def delete(key, options = {})
        @cookies[key] = nil
        super
      end

      # (see Proxy#clear)
      def clear(options = {})
        @backend.each_key { |key| @cookies[key] = nil }
        super
        self
      end

      # Reset the cookie store
      # This method is used by the middleware.
      def reset(cookies)
        @cookies, @backend = {}, cookies
      end
    end
  end
end