Sha256: cde7e18918d5b01bc910147ecb35748c54dde5428d4da5f96e1def1e54ce0767

Contents?: true

Size: 880 Bytes

Versions: 10

Compression:

Stored size: 880 Bytes

Contents

module Grape
  class Cookies

      def initialize
        @cookies = {}
        @send_cookies = {}
      end

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

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

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

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

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

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

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
grape-0.2.1.1 lib/grape/cookies.rb
grape-0.2.3 lib/grape/cookies.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/grape-0.2.2/lib/grape/cookies.rb
fragrant-0.0.4 vendor/grape/lib/grape/cookies.rb
grape-0.2.2 lib/grape/cookies.rb
fragrant-0.0.3 vendor/grape/lib/grape/cookies.rb
fragrant-0.0.2 vendor/grape/lib/grape/cookies.rb
fragrant-0.0.1 vendor/grape/lib/grape/cookies.rb
grape-0.2.1 lib/grape/cookies.rb
grape-0.2.0 lib/grape/cookies.rb