Class: Merb::Test::Cookie

Inherits:
Object show all
Defined in:
merb-core/lib/merb-core/test/helpers/cookie_jar.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Cookie) initialize(raw, default_host)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A new instance of Cookie



11
12
13
14
15
16
17
18
19
20
21
# File 'merb-core/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, options = raw.split(/[;,] */n, 2)
  
  @name, @value = Merb::Parse.query(@name_value_raw, ';').to_a.first
  @options = Merb::Parse.query(options, ';')
  
  @options.delete_if { |k, v| !v || v.empty? }
  
  @options["domain"] ||= default_host
end

Instance Attribute Details

- (Object) name (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'merb-core/lib/merb-core/test/helpers/cookie_jar.rb', line 8

def name
  @name
end

- (Object) value (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'merb-core/lib/merb-core/test/helpers/cookie_jar.rb', line 8

def value
  @value
end

Instance Method Details

- (Object) <=>(other)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



68
69
70
71
# File 'merb-core/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

- (Object) domain

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
# File 'merb-core/lib/merb-core/test/helpers/cookie_jar.rb', line 34

def domain
  @options["domain"]
end

- (Boolean) empty?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


29
30
31
# File 'merb-core/lib/merb-core/test/helpers/cookie_jar.rb', line 29

def empty?
  @value.nil? || @value.empty?
end

- (Boolean) expired?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


49
50
51
# File 'merb-core/lib/merb-core/test/helpers/cookie_jar.rb', line 49

def expired?
  expires && expires < Time.now
end

- (Object) expires

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
# File 'merb-core/lib/merb-core/test/helpers/cookie_jar.rb', line 44

def expires
  Time.parse(@options["expires"]) if @options["expires"]
end

- (Boolean) matches?(uri)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


63
64
65
# File 'merb-core/lib/merb-core/test/helpers/cookie_jar.rb', line 63

def matches?(uri)
  ! expired? && valid?(uri)
end

- (Object) path

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
# File 'merb-core/lib/merb-core/test/helpers/cookie_jar.rb', line 39

def path
  @options["path"] || "/"
end

- (Object) raw

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'merb-core/lib/merb-core/test/helpers/cookie_jar.rb', line 24

def raw
  @name_value_raw
end

- (Boolean) valid?(uri)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


54
55
56
57
58
59
60
# File 'merb-core/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