Restore and improve compatibility with ruby 1.8.

This commit is contained in:
Akinori MUSHA 2013-04-14 13:01:37 +09:00
parent 655fc9eb56
commit 6ec66d11ed
3 changed files with 37 additions and 21 deletions

View file

@ -3,29 +3,12 @@ require 'http/cookie/version'
require 'time'
require 'uri'
require 'domain_name'
require 'http/cookie/ruby_compat'
module HTTP
autoload :CookieJar, 'http/cookie_jar'
end
# In Ruby < 1.9.3 URI() does not accept a URI object.
if RUBY_VERSION < "1.9.3"
begin
URI(URI(''))
rescue
def URI(url) # :nodoc:
case url
when URI
url
when String
URI.parse(url)
else
raise ArgumentError, 'bad argument (expected URI object or URI string)'
end
end
end
end
# This class is used to represent an HTTP Cookie.
class HTTP::Cookie
# Maximum number of bytes per cookie (RFC 6265 6.1 requires 4096 at

View file

@ -0,0 +1,33 @@
class Array
def select!
i = 0
each_with_index { |x, j|
yield x or next
self[i] = x if i != j
i += 1
}
return nil if i == size
self[i..-1] = []
self
end unless method_defined?(:select!)
end
# In Ruby < 1.9.3 URI() does not accept a URI object.
if RUBY_VERSION < "1.9.3"
require 'uri'
begin
URI(URI(''))
rescue
def URI(url) # :nodoc:
case url
when URI
url
when String
URI.parse(url)
else
raise ArgumentError, 'bad argument (expected URI object or URI string)'
end
end
end
end

View file

@ -255,7 +255,7 @@ class HTTP::CookieJar
db_delete(cookie)
end
def each(uri = nil)
def each(uri = nil, &block)
now = Time.now
if uri
@st_cookies_for_domain ||=
@ -304,7 +304,7 @@ class HTTP::CookieJar
yield cookie
end
}
@sjar.each(uri, &proc)
@sjar.each(uri, &block)
else
@st_all_cookies ||=
@db.prepare(<<-'SQL')
@ -333,7 +333,7 @@ class HTTP::CookieJar
yield cookie
}
@sjar.each(&proc)
@sjar.each(&block)
end
self
end