module Atlas::Config

class: Atlas::Config: This class helps to handle configuration from YAML files

Public Class Methods

[](key) click to toggle source
# File lib/atlas/config.rb, line 35
def self.[](key)
  @config || Config.init
  @config[key]
end
config() click to toggle source
# File lib/atlas/config.rb, line 11
def self.config
  @config ||= {}
end
configure(source = nil) { |self| ... } click to toggle source
# File lib/atlas/config.rb, line 15
def self.configure(source = nil)
  config

  case source
  when /\.(yml|yaml)$/i then
    raise StandardError.new("The configuration file: #{config_file} does not exist") unless File.exist?(source)

    @config = ::YAML.safe_load(File.read(source))
  else
    yield self if block_given?
  end

  self
end
fetch(key, default_value = nil) click to toggle source
# File lib/atlas/config.rb, line 40
def self.fetch(key, default_value = nil)
  config
  if @config.keys.include?(key)
    @config[key]
  else
    default_value
  end
end
inspect() click to toggle source
# File lib/atlas/config.rb, line 30
def self.inspect
  config
  @config.inspect
end
method_missing(method, *arguments, &block) click to toggle source
Calls superclass method
# File lib/atlas/config.rb, line 53
def self.method_missing(method, *arguments, &block)
  config

  method_str = method.to_s

  case method_str
  when /(.+)=$/ then
    key          = method_str.delete('=').to_sym
    @config[key] = arguments.size == 1 ? arguments[0] : arguments
  when /(.+)\?$/ then
    key = method_str.delete('?').to_sym
    @config.keys.include?(key)
  else
    if @config.keys.include?(method)
      @config[method]
    elsif @config.keys.include?(method_str)
      @config[method_str]
    else
      super
    end
  end
end
respond_to_missing?() click to toggle source
# File lib/atlas/config.rb, line 49
def self.respond_to_missing?
  true
end