Sha256: 5e9fbb34bbb165d1edd7716a5add1cbc3302d7263079a07226c16db3558bd0dc
Contents?: true
Size: 1.67 KB
Versions: 1
Compression:
Stored size: 1.67 KB
Contents
# module Hdcore @log = Logger.new(STDOUT) # Default configuration values @config = { api_endpoint: 'core.hostdime.com/api/v1', public_key: nil, private_key: nil } @valid_config_keys = @config.keys class << self # Configure HDCore with an options hash. # @param [Hash] opts Configuration options hash # @option opts [String] :api_endpoint ('core.hostdime.com/api/v1') The HDCore API endpoint URI # @option opts [String] :public_key Your HDCore public key # @option opts [String] :private_key Your HDCore private key def configure opts = {} opts.each do |key, val| config[key.to_sym] = val if @valid_config_keys.include? key.to_sym end end # Configure HDCore with an external yaml config file. # @param [String] path_to_yaml_file Absolute path to yaml config file def configure_with path_to_yaml_file begin config = YAML::load(IO.read(path_to_yaml_file)) rescue Errno::ENOENT log.warn "YAML config file not found: using defaults instead"; return rescue Psych::SyntaxError log.warn "YAML config file has invalid syntax: using defaults instead"; return end configure(config) end # Current configuration hash def config @config end # For logging purposes def log @log end # @return [Bool] True if there are configuration keys that have no assigned value. def missing_config_values? config.values.include? nil end # @return [Array] Configuration keys that have no assigned value. def missing_config_values config.select{|k,v| v.nil?}.keys end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hdcore-0.0.1 | lib/hdcore/hdcore.rb |