Sha256: 60aa86986f66bc1d8ed77e745169579c81ba21919a54a161551a7862bfe6914b
Contents?: true
Size: 1.72 KB
Versions: 3
Compression:
Stored size: 1.72 KB
Contents
module Agcod class Configuration REQUIRED_OPTIONS = ["access_key", "secret_key", "partner_id", "uri", "discount_percentage" ] class << self attr_reader :options attr_accessor :logger def load(app_root = nil, env = nil) if app_root @app_root = app_root else @app_root = Rails.root if defined?(Rails) end if @app_root.nil? || !FileTest.exists?(config_filename = File.join(@app_root, 'config', 'agcod.yml')) raise Error::ConfigurationError, "Configuration for AGCOD not found" end config_file = File.read(config_filename) environment = Rails.env if defined?(Rails) environment = env if env @options = YAML.load(config_file)[environment] raise Error::ConfigurationError, "Configuration for AGCOD (#{ environment } environment) not found" unless @options validate_options @options end def set(opt = {}) @options ||= {} @options.merge!(opt) validate_options @options end def access_key @options["access_key"] end def secret_key @options["secret_key"] end def partner_id @options["partner_id"] end def uri @options["uri"] end def discount_percentage @options["discount_percentage"] end def verify_mode @options["verify_mode"] end private def validate_options REQUIRED_OPTIONS.each do |opt| if options[opt].nil? || options[opt] == "" raise Error::ConfigurationError, "#{opt} was not specified" end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
agcod-0.1.1 | lib/agcod/configuration.rb |
agcod-0.1.0 | lib/agcod/configuration.rb |
agcod-0.0.6 | lib/agcod/configuration.rb |