lib/bookmeter_scraper/configuration.rb in bookmeter_scraper-0.1.1 vs lib/bookmeter_scraper/configuration.rb in bookmeter_scraper-0.1.2

- old
+ new

@@ -1,18 +1,29 @@ -require 'yaml' - module BookmeterScraper class Configuration - attr_reader :mail, :password + attr_accessor :mail, :password - def initialize(config_file) - config = YAML.load_file(config_file) + def initialize(config_file = nil) + if config_file.nil? + @mail = @password = '' + return + end + + config = load_yaml_file(config_file) unless config.has_key?('mail') && config.has_key?('password') raise ConfigurationError, "#{config_file}: Invalid configuration file" end @mail = config['mail'] @password = config['password'] + end + + + private + + def load_yaml_file(config_file) + require 'yaml' + YAML.load_file(config_file) end end class ConfigurationError < StandardError; end end