+require 'yaml'
+
module Configuration
# Configurable Options
-
+ #
# We support a couple of different download methods. The :openuri
# method utilizes the ruby open-uri library, and provides its own
# progress bar with no external dependencies. The :wget method, on the
# other hand, requires GNU Wget (http://www.gnu.org/software/wget/),
# but will support auto-resume of partially-downloaded files for
# example.
- DOWNLOAD_METHOD = :openuri
- #DOWNLOAD_METHOD = :wget
- USER_AGENT = 'whatever-dl'
+ USERCONF_PATH = ENV['HOME'] + '/.whatever-dl.conf.yml'
+ @dict = {}
+
+ def initialize()
+ cfg = default_configuration()
+
+ # Now, load the user configuration which will override the
+ # variables defined above.
+ begin
+ user_config = YAML.load(File.open(USERCONF_PATH))
+
+ # We require ruby-1.9.x now so this should exist.
+ cfg.merge!(user_config)
+
+ rescue Errno::ENOENT
+ # If the user config file doesn't exist, whatever.
+ end
+
+ # Convert all of the keys to symbols.
+ cfg = cfg.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
+
+ @dict = cfg
+ end
+
+ def method_missing(sym, *args)
+ # Replace all missing method calls with dictionary lookups.
+ return @dict[sym]
+ end
+
+
+ private;
+
+ def default_configuration()
+ d = {}
+
+ d['download_method'] = 'openuri'
+ d['user_agent'] = 'whatever-dl'
+
+ return d
+ end
+
end