Sha256: a7110e6291bdb619b011a8c19b8bd1fc2989cd243e9fdc109acd5becfd60077b

Contents?: true

Size: 874 Bytes

Versions: 10

Compression:

Stored size: 874 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 { |name, value|
        cookie_value = value.is_a?(Hash) ? value : { :value => value }
        Rack::Utils.set_cookie_header! header, name, cookie_value
      }
    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

10 entries across 10 versions & 1 rubygems

Version Path
grape-0.6.0 lib/grape/cookies.rb
grape-0.5.0 lib/grape/cookies.rb
grape-0.4.1 lib/grape/cookies.rb
grape-0.4.0 lib/grape/cookies.rb
grape-0.3.2 lib/grape/cookies.rb
grape-0.3.1 lib/grape/cookies.rb
grape-0.3.0 lib/grape/cookies.rb
grape-0.2.6 lib/grape/cookies.rb
grape-0.2.5 lib/grape/cookies.rb
grape-0.2.4 lib/grape/cookies.rb