Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions lib/http/cookie_jar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 0 additions & 6 deletions test/test_http_cookie_jar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down