Sha256: eae818174ddcc926eec5b27b4efb12bfe72b63dd86235c024f330839edaae261

Contents?: true

Size: 846 Bytes

Versions: 17

Compression:

Stored size: 846 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

17 entries across 17 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/lib/grape/cookies.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/lib/grape/cookies.rb
grape-1.2.5 lib/grape/cookies.rb
grape-1.2.4 lib/grape/cookies.rb
grape-1.2.3 lib/grape/cookies.rb
grape-1.2.2 lib/grape/cookies.rb
grape-1.2.1 lib/grape/cookies.rb
grape-1.2.0 lib/grape/cookies.rb
grape-1.1.0 lib/grape/cookies.rb
grape-1.0.3 lib/grape/cookies.rb
grape-1.0.2 lib/grape/cookies.rb
grape-1.0.1 lib/grape/cookies.rb
grape-1.0.0 lib/grape/cookies.rb
grape-0.19.2 lib/grape/cookies.rb
grape-0.19.1 lib/grape/cookies.rb
grape-0.19.0 lib/grape/cookies.rb
grape-0.18.0 lib/grape/cookies.rb