Officially add AbstractStore#delete() as an API method.

This commit is contained in:
Akinori MUSHA 2013-03-28 01:04:45 +09:00
parent 19901a9d9c
commit 30e2915c1e
3 changed files with 31 additions and 5 deletions

View file

@ -50,6 +50,11 @@ class HTTP::CookieJar::AbstractStore
self
end
def delete(cookie)
raise
self
end
# Iterates over all cookies that are not expired.
#
# An optional argument +uri+ specifies a URI object indicating the
@ -80,7 +85,7 @@ class HTTP::CookieJar::AbstractStore
else
select(&:expired?)
end.each { |cookie|
add(cookie.expire)
delete(cookie)
}
# subclasses can optionally remove over-the-limit cookies.
self

View file

@ -57,7 +57,6 @@ class HTTP::CookieJar
path_cookies.delete(cookie.name)
self
end
private :delete
def each(uri = nil)
now = Time.now

View file

@ -137,7 +137,8 @@ class HTTP::CookieJar
st_update = @db.prepare("UPDATE moz_cookies SET baseDomain = :baseDomain WHERE id = :id")
@db.execute("SELECT id, host FROM moz_cookies") { |row|
domain = DomainName.new(row[:host]).domain
domain_name = DomainName.new(row[:host])
domain = domain_name.domain || domain_name.hostname
st_update.execute(:baseDomain => domain, :id => row[:id])
}
@ -214,6 +215,27 @@ class HTTP::CookieJar
self
end
def delete(cookie)
@st_delete ||=
@db.prepare(<<-'SQL')
DELETE FROM moz_cookies
WHERE appId = :appId AND
inBrowserElement = :inBrowserElement AND
name = :name AND
host = :host AND
path = :path
SQL
@st_delete.execute({
:appId => @app_id,
:inBrowserElement => @in_browser_element ? 1 : 0,
:name => cookie.name,
:host => cookie.dot_domain,
:path => cookie.path,
})
self
end
def each(uri = nil)
now = Time.now
if uri
@ -230,10 +252,10 @@ class HTTP::CookieJar
@db.prepare("UPDATE moz_cookies SET lastAccessed = :lastAccessed where id = :id")
thost = DomainName.new(uri.host)
tpath = HTTP::Cookie.normalize_path(uri.path)
tpath = uri.path
@st_cookies_for_domain.execute({
:baseDomain => thost.domain_name.domain,
:baseDomain => thost.domain || thost.hostname,
:appId => @app_id,
:inBrowserElement => @in_browser_element ? 1 : 0,
:expiry => now.to_i,