Class: Merb::Test::Cookie
- Defined in:
- lib/merb-core/test/helpers/cookie_jar.rb
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, default_host) ⇒ Cookie
constructor
:api: private.
-
#matches?(uri) ⇒ Boolean
:api: private.
-
#path ⇒ Object
:api: private.
-
#raw ⇒ Object
:api: private.
-
#valid?(uri) ⇒ Boolean
:api: private.
Constructor Details
#initialize(raw, default_host) ⇒ Cookie
:api: private
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/merb-core/test/helpers/cookie_jar.rb', line 11 def initialize(raw, default_host) # separate the name / value pair from the cookie options @name_value_raw, = raw.split(/[;,] */n, 2) @name, @value = Merb::Parse.query(@name_value_raw, ';').to_a.first @options = Merb::Parse.query(, ';') @options.delete_if { |k, v| !v || v.empty? } @options["domain"] ||= default_host end |
Instance Attribute Details
#name ⇒ Object (readonly)
:api: private
8 9 10 |
# File 'lib/merb-core/test/helpers/cookie_jar.rb', line 8 def name @name end |
#value ⇒ Object (readonly)
:api: private
8 9 10 |
# File 'lib/merb-core/test/helpers/cookie_jar.rb', line 8 def value @value end |
Instance Method Details
#<=>(other) ⇒ Object
:api: private
68 69 70 71 |
# File 'lib/merb-core/test/helpers/cookie_jar.rb', line 68 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
34 35 36 |
# File 'lib/merb-core/test/helpers/cookie_jar.rb', line 34 def domain @options["domain"] end |
#empty? ⇒ Boolean
:api: private
29 30 31 |
# File 'lib/merb-core/test/helpers/cookie_jar.rb', line 29 def empty? @value.nil? || @value.empty? end |
#expired? ⇒ Boolean
:api: private
49 50 51 |
# File 'lib/merb-core/test/helpers/cookie_jar.rb', line 49 def expired? expires && expires < Time.now end |
#expires ⇒ Object
:api: private
44 45 46 |
# File 'lib/merb-core/test/helpers/cookie_jar.rb', line 44 def expires Time.parse(@options["expires"]) if @options["expires"] end |
#matches?(uri) ⇒ Boolean
:api: private
63 64 65 |
# File 'lib/merb-core/test/helpers/cookie_jar.rb', line 63 def matches?(uri) ! expired? && valid?(uri) end |
#path ⇒ Object
:api: private
39 40 41 |
# File 'lib/merb-core/test/helpers/cookie_jar.rb', line 39 def path @options["path"] || "/" end |
#raw ⇒ Object
:api: private
24 25 26 |
# File 'lib/merb-core/test/helpers/cookie_jar.rb', line 24 def raw @name_value_raw end |
#valid?(uri) ⇒ Boolean
:api: private
54 55 56 57 58 59 60 |
# File 'lib/merb-core/test/helpers/cookie_jar.rb', line 54 def valid?(uri) domain_ = domain.index('.') == 0 ? domain[1..-1] : domain uri_path = uri.path.blank? ? "/" : uri.path uri.host =~ Regexp.new("#{Regexp.escape(domain_)}$") && uri_path =~ Regexp.new("^#{Regexp.escape(path)}") end |