class ApiRecipes::Configuration

Attributes

apis_files_paths[RW]
log_level[RW]
log_to[RW]
print_urls[RW]

Public Instance Methods

apis_configs() click to toggle source
# File lib/api_recipes/configuration.rb, line 16
def apis_configs
  unless @apis_configs
    @apis_configs = {}
  end
  @apis_configs
end
apis_configs=(configs = {}) click to toggle source
# File lib/api_recipes/configuration.rb, line 10
def apis_configs=(configs = {})
  raise ArgumentError, 'apis_configs must be an Hash' unless configs.is_a? Hash

  @apis_configs = configs.deep_symbolize_keys
end
apis_files_paths=(paths = []) click to toggle source
# File lib/api_recipes/configuration.rb, line 23
def apis_files_paths=(paths = [])
  raise ArgumentError, 'apis_files_paths must be an Array' unless paths.is_a? Array

  @apis_files_paths = paths
  @apis_files_paths.each do |file_path|
    template = ERB.new File.read File.expand_path(file_path)
    data = begin
             YAML.load(template.result(binding), aliases: true)
           rescue ArgumentError
             YAML.load(template.result binding)
           end.deep_symbolize_keys
    # Merge file contents into apis_configs
    data.each do |api, params|
      if apis_configs[api]
        logger.debug "File at #{file_path} overrides config for '#{api}' API"
      end
      apis_configs[api] = params
    end
  end
end
logger() click to toggle source
# File lib/api_recipes/configuration.rb, line 55
def logger
  unless @logger
    log = ::Logger.new(log_to || STDOUT)
    log.level    = normalize_log_level
    log.progname = 'ApiRecipes'
    @logger = log
  end

  @logger
end
logger=(logger) click to toggle source
# File lib/api_recipes/configuration.rb, line 51
def logger=(logger)
  @logger = logger
end
setup() click to toggle source
# File lib/api_recipes/configuration.rb, line 66
def setup
  ApiRecipes._aprcps_define_global_apis
end

Private Instance Methods

normalize_log_level() click to toggle source

@private

# File lib/api_recipes/configuration.rb, line 73
def normalize_log_level
  case @log_level
  when :debug, ::Logger::DEBUG, 'debug' then ::Logger::DEBUG
  when :info,  ::Logger::INFO,  'info'  then ::Logger::INFO
  when :warn,  ::Logger::WARN,  'warn'  then ::Logger::WARN
  when :error, ::Logger::ERROR, 'error' then ::Logger::ERROR
  when :fatal, ::Logger::FATAL, 'fatal' then ::Logger::FATAL
  else
    ENV['LOG_LEVEL'] || Logger::DEBUG
  end
end