Class: Rack::Test::Cookie
- Inherits:
-
Object
- Object
- Rack::Test::Cookie
- Includes:
- Utils
- Defined in:
- lib/rack/test/cookie_jar.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
:api: private.
-
#value ⇒ Object
readonly
:api: private.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
:api: private.
-
#domain ⇒ Object
:api: private.
-
#empty? ⇒ Boolean
:api: private.
-
#expired? ⇒ Boolean
:api: private.
-
#expires ⇒ Object
:api: private.
-
#initialize(raw, uri = nil, default_host = DEFAULT_HOST) ⇒ Cookie
constructor
:api: private.
-
#matches?(uri) ⇒ Boolean
:api: private.
-
#path ⇒ Object
:api: private.
-
#raw ⇒ Object
:api: private.
- #replaces?(other) ⇒ Boolean
- #secure? ⇒ Boolean
-
#valid?(uri) ⇒ Boolean
:api: private.
Constructor Details
#initialize(raw, uri = nil, default_host = DEFAULT_HOST) ⇒ Cookie
:api: private
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rack/test/cookie_jar.rb', line 14 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, = raw.split(/[;,] */n, 2) @name, @value = parse_query(@name_value_raw, ';').to_a.first @options = parse_query(, ';') @options["domain"] ||= (uri.host || default_host) @options["path"] ||= uri.path.sub(/\/[^\/]*\Z/, "") end |
Instance Attribute Details
#name ⇒ Object (readonly)
:api: private
11 12 13 |
# File 'lib/rack/test/cookie_jar.rb', line 11 def name @name end |
#value ⇒ Object (readonly)
:api: private
11 12 13 |
# File 'lib/rack/test/cookie_jar.rb', line 11 def value @value end |
Instance Method Details
#<=>(other) ⇒ Object
:api: private
86 87 88 89 |
# File 'lib/rack/test/cookie_jar.rb', line 86 def <=>(other) # Orders the cookies from least specific to most [name, path, domain.reverse] <=> [other.name, other.path, other.domain.reverse] end |
#domain ⇒ Object
:api: private
43 44 45 |
# File 'lib/rack/test/cookie_jar.rb', line 43 def domain @options["domain"] end |
#empty? ⇒ Boolean
:api: private
38 39 40 |
# File 'lib/rack/test/cookie_jar.rb', line 38 def empty? @value.nil? || @value.empty? end |
#expired? ⇒ Boolean
:api: private
62 63 64 |
# File 'lib/rack/test/cookie_jar.rb', line 62 def expired? expires && expires < Time.now end |
#expires ⇒ Object
:api: private
57 58 59 |
# File 'lib/rack/test/cookie_jar.rb', line 57 def expires Time.parse(@options["expires"]) if @options["expires"] end |
#matches?(uri) ⇒ Boolean
:api: private
81 82 83 |
# File 'lib/rack/test/cookie_jar.rb', line 81 def matches?(uri) ! expired? && valid?(uri) end |
#path ⇒ Object
:api: private
52 53 54 |
# File 'lib/rack/test/cookie_jar.rb', line 52 def path @options["path"].strip || "/" end |
#raw ⇒ Object
:api: private
33 34 35 |
# File 'lib/rack/test/cookie_jar.rb', line 33 def raw @name_value_raw end |
#replaces?(other) ⇒ Boolean
28 29 30 |
# File 'lib/rack/test/cookie_jar.rb', line 28 def replaces?(other) [name.downcase, domain, path] == [other.name.downcase, other.domain, other.path] end |
#secure? ⇒ Boolean
47 48 49 |
# File 'lib/rack/test/cookie_jar.rb', line 47 def secure? @options.has_key?("secure") end |
#valid?(uri) ⇒ Boolean
:api: private
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rack/test/cookie_jar.rb', line 67 def valid?(uri) uri ||= default_uri if uri.host.nil? uri.host = @default_host end real_domain = domain =~ /^\./ ? domain[1..-1] : domain (!secure? || (secure? && uri.scheme == "https")) && uri.host =~ Regexp.new("#{Regexp.escape(real_domain)}$", Regexp::IGNORECASE) && uri.path =~ Regexp.new("^#{Regexp.escape(path)}") end |