Skip to content

Commit

Permalink
Mechanize::Cookie no longer inherits WEBrick::Cookie.
Browse files Browse the repository at this point in the history
After overriding methods and adding features on top, today we have
little to gain from WEBrick::Cookie as the superclass.
  • Loading branch information
knu committed Nov 8, 2011
1 parent 5bb10d0 commit 8c18e54
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/mechanize/cookie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
require 'domain_name'

# This class is used to represent an HTTP Cookie.
class Mechanize::Cookie < WEBrick::Cookie
class Mechanize::Cookie
attr_reader :name
attr_accessor :value, :version
attr_accessor :domain, :path, :secure
attr_accessor :comment, :max_age

attr_accessor :session

Expand All @@ -23,17 +27,20 @@ class Mechanize::Cookie < WEBrick::Cookie
# new("name" => "uid", "value" => "a12345", "Domain" => 'www.example.org')
#
def initialize(*args)
@version = 0 # Netscape Cookie

@domain = @path = @secure = @comment = @max_age =
@expires = @comment_url = @discard = @port = nil

case args.size
when 2
super(*args)
@name, @value = *args
@for_domain = false
return
when 3
name, value, attr_hash = *args
super(name, value)
@name, @value, attr_hash = *args
when 1
attr_hash = args.first
super(nil, nil)
else
raise ArgumentError, "wrong number of arguments (#{args.size} for 1-3)"
end
Expand Down Expand Up @@ -148,6 +155,14 @@ def domain=(domain)
set_domain(@domain_name.hostname)
end

def expires=(t)
@expires = t && (t.is_a?(Time) ? t.httpdate : t.to_s)
end

def expires
@expires && Time.parse(@expires)
end

def expired?
return false unless expires
Time.now > expires
Expand Down

0 comments on commit 8c18e54

Please sign in to comment.