Module: TrophyScraper

Defined in:
lib/trophy_scraper.rb

Constant Summary collapse

DEFAULTS =

Default options. Overriden by values in _config.yml or command-line opts. (Strings rather symbols used for compatability with YAML)

{
  'config' => '~/.trophy_scraper.yml',
  'db' => '',
  'log_level' => Logger::INFO,
  'log_dest' => STDOUT,
  'db' => "sqlite3://%s/trophy_scraper.db" % File.expand_path("~"),
  'db_log_level' => "fatal",
  'db_log_dest' => STDOUT
}

Class Method Summary collapse

Class Method Details

.configuration(override) ⇒ Object

Generate a TrophyScraper configuration Hash by merging the default options with anything in config.yml, and adding the given options on top

+override+ is a Hash of config directives

Returns Hash



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/trophy_scraper.rb', line 43

def self.configuration(override)
  # config.yml may override default source location, but until
  # then, we need to know where to look for config.yml
  source = override['config'] || TrophyScraper::DEFAULTS['config']

  # Get configuration from <source>
  config_file = File.expand_path(source)
  begin
    config = YAML.load_file(config_file)
    raise "Invalid configuration - #{config_file}" if !config.is_a?(Hash)
    STDOUT.puts "Configuration from #{config_file}"
  rescue => err
    STDERR.puts "WARNING: Could not read configuration. Using defaults (and options)."
    STDERR.puts "\t" + err.to_s
    config = {}
  end

  # Merge DEFAULTS < config.yml < override
  TrophyScraper::DEFAULTS.deep_merge(config).deep_merge(override)
end

.versionObject



64
65
66
67
# File 'lib/trophy_scraper.rb', line 64

def self.version
  yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
  "#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
end