Class Rack::Test::Cookie

  1. lib/rack/test/cookie_jar.rb (view online)
Parent: Object

Methods

public class

  1. new

public instance

  1. <=>
  2. domain
  3. empty?
  4. expired?
  5. expires
  6. matches?
  7. path
  8. raw
  9. replaces?
  10. secure?
  11. valid?

protected instance

  1. default_uri

Included modules

  1. Rack::Utils

Attributes

name [R] :api: private
value [R] :api: private

Public class methods

new (raw, uri = nil, default_host = DEFAULT_HOST)

:api: private

[show source]
# File lib/rack/test/cookie_jar.rb, line 12
      def initialize(raw, uri = nil, default_host = DEFAULT_HOST)
        @default_host = default_host
        uri ||= default_uri

        # separate the name / value pair from the cookie options
        @name_value_raw, options = raw.split(/[;,] */n, 2)

        @name, @value = parse_query(@name_value_raw, ';').to_a.first
        @options = parse_query(options, ';')

        @options["domain"]  ||= (uri.host || default_host)
        @options["path"]    ||= uri.path.sub(/\/[^\/]*\Z/, "")
      end

Public instance methods

<=> (other)

:api: private

[show source]
# File lib/rack/test/cookie_jar.rb, line 83
      def <=>(other)
        # Orders the cookies from least specific to most
        [name, path, domain.reverse] <=> [other.name, other.path, other.domain.reverse]
      end
domain ()

:api: private

[show source]
# File lib/rack/test/cookie_jar.rb, line 41
      def domain
        @options["domain"]
      end
empty? ()

:api: private

[show source]
# File lib/rack/test/cookie_jar.rb, line 36
      def empty?
        @value.nil? || @value.empty?
      end
expired? ()

:api: private

[show source]
# File lib/rack/test/cookie_jar.rb, line 60
      def expired?
        expires && expires < Time.now
      end
expires ()

:api: private

[show source]
# File lib/rack/test/cookie_jar.rb, line 55
      def expires
        Time.parse(@options["expires"]) if @options["expires"]
      end
matches? (uri)

:api: private

[show source]
# File lib/rack/test/cookie_jar.rb, line 78
      def matches?(uri)
        ! expired? && valid?(uri)
      end
path ()

:api: private

[show source]
# File lib/rack/test/cookie_jar.rb, line 50
      def path
        @options["path"].strip || "/"
      end
raw ()

:api: private

[show source]
# File lib/rack/test/cookie_jar.rb, line 31
      def raw
        @name_value_raw
      end
replaces? (other)
[show source]
# File lib/rack/test/cookie_jar.rb, line 26
      def replaces?(other)
        [name.downcase, domain, path] == [other.name.downcase, other.domain, other.path]
      end
secure? ()
[show source]
# File lib/rack/test/cookie_jar.rb, line 45
      def secure?
        @options.has_key?("secure")
      end
valid? (uri)

:api: private

[show source]
# File lib/rack/test/cookie_jar.rb, line 65
      def valid?(uri)
        uri ||= default_uri

        if uri.host.nil?
          uri.host = @default_host
        end

        (!secure? || (secure? && uri.scheme == "https")) &&
        uri.host =~ Regexp.new("#{Regexp.escape(domain)}$", Regexp::IGNORECASE) &&
        uri.path =~ Regexp.new("^#{Regexp.escape(path)}")
      end

Protected instance methods

default_uri ()
[show source]
# File lib/rack/test/cookie_jar.rb, line 90
      def default_uri
        URI.parse("//" + @default_host + "/")
      end