Fix hand-made autoloading to allow directly referencing MozillaStore.

This commit is contained in:
Akinori MUSHA 2013-04-16 00:37:10 +09:00
parent ded02f8327
commit d806955f57
2 changed files with 22 additions and 1 deletions

View file

@ -9,6 +9,27 @@ class HTTP::CookieJar
require 'http/cookie_jar/abstract_store'
require 'http/cookie_jar/abstract_saver'
class << self
def const_missing(name)
case name.to_s
when /\A([A-Za-z]+)Store\z/
file = 'http/cookie_jar/%s_store' % $1.downcase
when /\A([A-Za-z]+)Saver\z/
file = 'http/cookie_jar/%s_saver' % $1.downcase
end
begin
require file
rescue LoadError => e
raise NameError, 'can\'t resolve constant %s; failed to load %s' % [name, file]
end
if const_defined?(name)
const_get(name)
else
raise NameError, 'can\'t resolve constant %s after loading %s' % [name, file]
end
end
end
attr_reader :store
# Generates a new cookie jar.

View file

@ -94,7 +94,7 @@ class HTTP::CookieJar
@filename = options[:filename] or raise ArgumentError, ':filename option is missing'
@sjar = HashStore.new
@sjar = HTTP::CookieJar::HashStore.new
@db = Database.new(@filename)