lib/pupa/runner.rb in pupa-0.1.4 vs lib/pupa/runner.rb in pupa-0.1.5

- old
+ new

@@ -9,21 +9,23 @@ # @param [Hash] defaults change any default options def initialize(processor_class, defaults = {}) @processor_class = processor_class @options = OpenStruct.new({ - actions: [], - tasks: [], - output_dir: File.expand_path('scraped_data', Dir.pwd), - pipelined: false, - cache_dir: File.expand_path('web_cache', Dir.pwd), - expires_in: 86400, # 1 day - value_max_bytes: 1048576, # 1 MB - database_url: 'mongodb://localhost:27017/pupa', - validate: true, - level: 'INFO', - dry_run: false, + actions: [], + tasks: [], + output_dir: File.expand_path('scraped_data', Dir.pwd), + pipelined: false, + cache_dir: File.expand_path('web_cache', Dir.pwd), + expires_in: 86400, # 1 day + value_max_bytes: 1048576, # 1 MB + memcached_username: nil, + memcached_password: nil, + database_url: 'mongodb://localhost:27017/pupa', + validate: true, + level: 'INFO', + dry_run: false, }.merge(defaults)) @actions = { 'scrape' => 'Scrapes data from online sources', 'import' => 'Imports scraped data into a database', @@ -84,11 +86,17 @@ options.expires_in = v end opts.on('--value_max_bytes BYTES', "The maximum Memcached item size") do |v| options.value_max_bytes = v end - opts.on('-d', '--database_url SCHEME://USERNAME:PASSWORD@HOST:PORT/DATABASE', 'The database URL') do |v| + opts.on('--memcached_username USERNAME', "The Memcached username") do |v| + options.memcached_username = v + end + opts.on('--memcached_password USERNAME', "The Memcached password") do |v| + options.memcached_password = v + end + opts.on('-d', '--database_url', 'The database URL (e.g. mongodb://USER:PASSWORD@localhost:27017/pupa or postgres://USER:PASSWORD@localhost:5432/pupa') do |v| options.database_url = v end opts.on('--[no-]validate', 'Validate JSON documents') do |v| options.validate = v end @@ -145,10 +153,12 @@ processor = @processor_class.new(options.output_dir, pipelined: options.pipelined, cache_dir: options.cache_dir, expires_in: options.expires_in, value_max_bytes: options.value_max_bytes, + memcached_username: options.memcached_username, + memcached_password: options.memcached_password, database_url: options.database_url, validate: options.validate, level: options.level, options: Hash[*rest]) @@ -163,10 +173,10 @@ puts "actions: #{options.actions.join(', ')}" puts "tasks: #{options.tasks.join(', ')}" end if options.level == 'DEBUG' - %w(output_dir pipelined cache_dir expires_in value_max_bytes database_url validate level).each do |option| + %w(output_dir pipelined cache_dir expires_in value_max_bytes memcached_username memcached_password database_url validate level).each do |option| puts "#{option}: #{options[option]}" end unless rest.empty? puts "options: #{rest.join(' ')}" end