Make each(uri) not fail if a non-HTTP URL is given.

Fix documents with #each.  The uri argument was not made a keyword
argument.

Guarantee that the +uri+ given to AbstractStore#each() is a URI
object.

Make HashStore#each return self as required.
This commit is contained in:
Akinori MUSHA 2013-03-15 11:33:54 +09:00
parent 9d3975f641
commit 8be03978a0
4 changed files with 18 additions and 22 deletions

View file

@ -67,21 +67,19 @@ class HTTP::CookieJar
# Iterates over all cookies that are not expired.
#
# Available option keywords are below:
# An optional argument +uri+ specifies a URI/URL indicating the
# destination of the cookies being selected. Every cookie yielded
# should be good to send to the given URI,
# i.e. cookie.valid_for_uri?(uri) evaluates to true.
#
# * +uri+
#
# Specify a URI/URL indicating the destination of the cookies
# being selected. Every cookie yielded should be good to send to
# the given URI, i.e. cookie.valid_for_uri?(uri) evaluates to
# true.
#
# If (and only if) this option is given, last access time of each
# cookie is updated to the current time.
# If (and only if) the +uri+ option is given, last access time of
# each cookie is updated to the current time.
def each(uri = nil, &block)
block_given? or return enum_for(__method__, uri)
if uri
uri = URI(uri)
return self unless URI::HTTP === uri && uri.host
block = proc { |cookie|
yield cookie if cookie.valid_for_uri?(uri)
}

View file

@ -54,18 +54,14 @@ class HTTP::CookieJar::AbstractStore
# Iterates over all cookies that are not expired.
#
# Available option keywords are below:
# An optional argument +uri+ specifies a URI object indicating the
# destination of the cookies being selected. Every cookie yielded
# should be good to send to the given URI,
# i.e. cookie.valid_for_uri?(uri) evaluates to true.
#
# * +uri+
#
# Specify a URI object indicating the destination of the cookies
# being selected. Every cookie yielded should be good to send to
# the given URI, i.e. cookie.valid_for_uri?(uri) evaluates to
# true.
#
# If (and only if) this option is given, last access time of each
# cookie is updated to the current time.
def each(options = nil, &block)
# If (and only if) the +uri+ option is given, last access time of
# each cookie is updated to the current time.
def each(uri = nil, &block)
raise
self
end

View file

@ -51,7 +51,6 @@ class HTTP::CookieJar
def each(uri = nil)
if uri
uri = URI(uri)
thost = DomainName.new(uri.host)
tpath = HTTP::Cookie.normalize_path(uri.path)
@jar.each { |domain, paths|
@ -83,6 +82,7 @@ class HTTP::CookieJar
}
}
end
self
end
def clear

View file

@ -276,6 +276,8 @@ class TestHTTPCookieJar < Test::Unit::TestCase
assert_raises(ArgumentError) {
@jar.add(HTTP::Cookie.new(cookie_values(:origin => url)))
}
assert_equal(0, @jar.cookies(url).length)
end
def test_clear