diff --git a/lib/http/cookie_jar.rb b/lib/http/cookie_jar.rb index ef5429b..0f8c1f6 100644 --- a/lib/http/cookie_jar.rb +++ b/lib/http/cookie_jar.rb @@ -6,26 +6,12 @@ # any particular website. class HTTP::CookieJar - 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 - 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 + autoload :AbstractSaver, 'http/cookie_jar/abstract_saver' + autoload :AbstractStore, 'http/cookie_jar/abstract_store' + autoload :CookiestxtSaver, 'http/cookie_jar/cookiestxt_saver' + autoload :HashStore, 'http/cookie_jar/hash_store' + autoload :MozillaStore, 'http/cookie_jar/mozilla_store' + autoload :YamlSaver, 'http/cookie_jar/yaml_saver' attr_reader :store diff --git a/test/test_http_cookie_jar.rb b/test/test_http_cookie_jar.rb index bf96996..0c94e28 100644 --- a/test/test_http_cookie_jar.rb +++ b/test/test_http_cookie_jar.rb @@ -3,12 +3,6 @@ module TestHTTPCookieJar class TestAutoloading < Test::Unit::TestCase - def test_nonexistent_store - assert_raises(NameError) { - HTTP::CookieJar::NonexistentStore - } - end - def test_erroneous_store Dir.mktmpdir { |dir| Dir.mkdir(File.join(dir, 'http'))