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.
- #http_only? ⇒ Boolean
-
#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
- #to_h ⇒ Object (also: #to_hash)
-
#valid?(uri) ⇒ Boolean
:api: private.
Constructor Details
#initialize(raw, uri = nil, default_host = DEFAULT_HOST) ⇒ Cookie
:api: private
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rack/test/cookie_jar.rb', line 13 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
10 11 12 |
# File 'lib/rack/test/cookie_jar.rb', line 10 def name @name end |
#value ⇒ Object (readonly)
:api: private
10 11 12 |
# File 'lib/rack/test/cookie_jar.rb', line 10 def value @value end |
Instance Method Details
#<=>(other) ⇒ Object
:api: private
87 88 89 90 |
# File 'lib/rack/test/cookie_jar.rb', line 87 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
42 43 44 |
# File 'lib/rack/test/cookie_jar.rb', line 42 def domain @options['domain'] end |
#empty? ⇒ Boolean
:api: private
37 38 39 |
# File 'lib/rack/test/cookie_jar.rb', line 37 def empty? @value.nil? || @value.empty? end |
#expired? ⇒ Boolean
:api: private
65 66 67 |
# File 'lib/rack/test/cookie_jar.rb', line 65 def expired? expires && expires < Time.now end |
#expires ⇒ Object
:api: private
60 61 62 |
# File 'lib/rack/test/cookie_jar.rb', line 60 def expires Time.parse(@options['expires']) if @options['expires'] end |
#http_only? ⇒ Boolean
50 51 52 |
# File 'lib/rack/test/cookie_jar.rb', line 50 def http_only? @options.key?('HttpOnly') end |
#matches?(uri) ⇒ Boolean
:api: private
82 83 84 |
# File 'lib/rack/test/cookie_jar.rb', line 82 def matches?(uri) !expired? && valid?(uri) end |
#path ⇒ Object
:api: private
55 56 57 |
# File 'lib/rack/test/cookie_jar.rb', line 55 def path ([*@options['path']].first.split(',').first || '/').strip end |
#raw ⇒ Object
:api: private
32 33 34 |
# File 'lib/rack/test/cookie_jar.rb', line 32 def raw @name_value_raw end |
#replaces?(other) ⇒ Boolean
27 28 29 |
# File 'lib/rack/test/cookie_jar.rb', line 27 def replaces?(other) [name.downcase, domain, path] == [other.name.downcase, other.domain, other.path] end |
#secure? ⇒ Boolean
46 47 48 |
# File 'lib/rack/test/cookie_jar.rb', line 46 def secure? @options.key?('secure') end |
#to_h ⇒ Object Also known as: to_hash
92 93 94 95 96 97 98 |
# File 'lib/rack/test/cookie_jar.rb', line 92 def to_h @options.merge( 'value' => @value, 'HttpOnly' => http_only?, 'secure' => secure? ) end |
#valid?(uri) ⇒ Boolean
:api: private
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rack/test/cookie_jar.rb', line 70 def valid?(uri) uri ||= default_uri uri.host = @default_host if uri.host.nil? 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 |