Sha256: 9aadc3d7c883b004c029372cb3a7b83d1864cfc367ebacbf747a7a26d6a61d80

Contents?: true

Size: 712 Bytes

Versions: 1

Compression:

Stored size: 712 Bytes

Contents

require 'yaml'

module RestApiClient

  # Configuration defaults
  @config = {
      :log_level => 'verbose',
      :service_key => ''
  }

  # Configure through hash
  def self.configure(opts = {})
    opts.each { |k, v| @config[k.to_sym] = v }
  end

  # Configure through yaml file
  def self.configure_with(path_to_yaml_file)
    begin
      config = YAML::load(IO.read(path_to_yaml_file))
    rescue Errno::ENOENT
      log(:warning, "YAML configuration file couldn't be found. Using defaults."); return
    rescue Psych::SyntaxError
      log(:warning, 'YAML configuration file contains invalid syntax. Using defaults.'); return
    end

    configure(config)
  end

  def self.config
    @config
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rest-api-client-0.1.0 lib/rest/api/client/config.rb