class Lookout::Rack::Cookie
Attributes
name[R]
Public Class Methods
new(header, uri = nil, default_host = Lookout::Rack::DefaultHost)
click to toggle source
# File lib/lookout-rack-1.0/cookie.rb, line 5 def initialize(header, uri = nil, default_host = Lookout::Rack::DefaultHost) @default_host = default_host uri ||= default_uri @cookie, options = header.split(/[;,] */n, 2) @name, @value = Rack::Utils.parse_query(@cookie, ';').to_a.first @options = Hash[Rack::Utils.parse_query(options, ';').map{ |k, v| [k.downcase, v] }] @options['domain'] ||= uri.host || default_host @options['path'] ||= uri.path.sub(%r{/[^/]*\z}, '') end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/lookout-rack-1.0/cookie.rb, line 40 def <=>(other) [name.downcase, path, domain.reverse] <=> [other.name.downcase, other.path, other.domain.reverse] end
empty?()
click to toggle source
# File lib/lookout-rack-1.0/cookie.rb, line 18 def empty? @value.nil? or @value.empty? end
eql?(other)
click to toggle source
# File lib/lookout-rack-1.0/cookie.rb, line 36 def eql?(other) self.class === other and self == other end
hash()
click to toggle source
# File lib/lookout-rack-1.0/cookie.rb, line 45 def hash name.downcase.hash ^ path.hash ^ domain.hash end
matches?(uri)
click to toggle source
# File lib/lookout-rack-1.0/cookie.rb, line 32 def matches?(uri) valid? uri and not expired? end
to_s()
click to toggle source
# File lib/lookout-rack-1.0/cookie.rb, line 49 def to_s @cookie end
valid?(uri)
click to toggle source
# File lib/lookout-rack-1.0/cookie.rb, line 22 def valid?(uri) uri ||= default_uri uri.host ||= @default_host real_domain = domain.start_with?('.') ? domain[1..-1] : domain secure? uri and uri.host.downcase.end_with? real_domain.downcase and uri.path.start_with? path end
Protected Instance Methods
domain()
click to toggle source
# File lib/lookout-rack-1.0/cookie.rb, line 57 def domain @options['domain'] end
path()
click to toggle source
# File lib/lookout-rack-1.0/cookie.rb, line 61 def path @options['path'].strip end
Private Instance Methods
default_uri()
click to toggle source
# File lib/lookout-rack-1.0/cookie.rb, line 67 def default_uri URI('//%s/' % @default_host) end
expired?()
click to toggle source
# File lib/lookout-rack-1.0/cookie.rb, line 75 def expired? @options['expires'] and Time.parse(@options['expires']) < Time.now end
secure?(uri)
click to toggle source
# File lib/lookout-rack-1.0/cookie.rb, line 71 def secure?(uri) not @options.include? 'secure' or uri.scheme == 'https' end