From d806955f5761b870fdc5ee0364d75c404b582b3c Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Tue, 16 Apr 2013 00:37:10 +0900 Subject: [PATCH] Fix hand-made autoloading to allow directly referencing MozillaStore. --- lib/http/cookie_jar.rb | 21 +++++++++++++++++++++ lib/http/cookie_jar/mozilla_store.rb | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/http/cookie_jar.rb b/lib/http/cookie_jar.rb index f1ba2d1..9102eef 100644 --- a/lib/http/cookie_jar.rb +++ b/lib/http/cookie_jar.rb @@ -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. diff --git a/lib/http/cookie_jar/mozilla_store.rb b/lib/http/cookie_jar/mozilla_store.rb index 961240b..46f7aa8 100644 --- a/lib/http/cookie_jar/mozilla_store.rb +++ b/lib/http/cookie_jar/mozilla_store.rb @@ -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)