module Ovchipkaart

Constants

CONFIGURATIONS_KEYS
MANDATORY_CONFIGURATION

Configuration

VERSION

Public Class Methods

config() click to toggle source
# File lib/ovchipkaart.rb, line 18
def self.config
  @config
end
configure(options = {}) click to toggle source

Configuration with a hash

# File lib/ovchipkaart.rb, line 23
def self.configure(options = {})
  MANDATORY_CONFIGURATION.each_key do |mandatory_option|
    unless options.keys.map(&:to_sym).include?(mandatory_option)
      raise ConfigurationError, 'Username and password are mandatory configuration options'
    end
  end

  options.keys.map(&:to_sym).each do |given_configuration_key|
    unless CONFIGURATIONS_KEYS.keys.include? given_configuration_key
      raise ConfigurationError, 'Unknown configuration given'
    end
  end

  options.each { |key, value| @config[key.to_sym] = value }
end
configure_with(path_to_yaml_file) click to toggle source

Configuration with a YAML file

# File lib/ovchipkaart.rb, line 40
def self.configure_with(path_to_yaml_file)
  begin
    config = YAML::load(IO.read(path_to_yaml_file))
  rescue Errno::ENOENT
    raise ConfigurationError, 'YAML configuration file not found'
  rescue Psych::SyntaxError
    raise ConfigurationError, 'YAML configuration file contains invalid syntax'
  end

  configure(config)
end