Sha256: f8e0f28376f7d4b29b7dfe434d717ec8a0b6520d5387172c47e61e964eb792ac
Contents?: true
Size: 1.69 KB
Versions: 2
Compression:
Stored size: 1.69 KB
Contents
# module Hdcore @log = Logger.new(STDOUT) # Default configuration values @config = { :api_endpoint => 'https://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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hdcore-0.0.7 | lib/hdcore/hdcore.rb |
hdcore-0.0.6 | lib/hdcore/hdcore.rb |