Sha256: 33024120f938f86be12d2d553be79bea7c5e538b7e070863615d6f8d882fce7c

Contents?: true

Size: 848 Bytes

Versions: 7

Compression:

Stored size: 848 Bytes

Contents

module Grape
  class Cookies
    def initialize
      @cookies = {}
      @send_cookies = {}
    end

    def read(request)
      request.cookies.each do |name, value|
        @cookies[name.to_s] = value
      end
    end

    def write(header)
      @cookies.select { |key, value| @send_cookies[key] == true }.each do |name, value|
        cookie_value = value.is_a?(Hash) ? value : { value: value }
        Rack::Utils.set_cookie_header! header, name, cookie_value
      end
    end

    def [](name)
      @cookies[name.to_s]
    end

    def []=(name, value)
      @cookies[name.to_s] = value
      @send_cookies[name.to_s] = true
    end

    def each(&block)
      @cookies.each(&block)
    end

    def delete(name, opts = {})
      options = opts.merge(value: 'deleted', expires: Time.at(0))
      self.[]=(name, options)
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
grape-security-0.8.0 lib/grape/cookies.rb
grape-0.11.0 lib/grape/cookies.rb
grape-0.10.1 lib/grape/cookies.rb
grape-0.10.0 lib/grape/cookies.rb
grape-0.9.0 lib/grape/cookies.rb
grape-0.8.0 lib/grape/cookies.rb
grape-0.7.0 lib/grape/cookies.rb