Class: SugarfreeConfig::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sugarfree-config.rb

Overview

Config base object. Caches the configuration in memory an acts as a factory for the ConfigIterators needed to get config values

Constant Summary collapse

DEFAULT_CONFIG_FILE =

Conifg file is expected at “#RAILS_ROOT/config/config.yml”

Rails.root.join('config', 'config.yml')

Instance Method Summary collapse

Constructor Details

#initialize(force_reload = false) ⇒ Config

Creates a new config object and load the config file into memory



65
66
67
# File 'lib/sugarfree-config.rb', line 65

def initialize(force_reload = false)
  @force_reload = force_reload
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object

Here is the magic. The first request to config returns a new ConfigIterator that will handle the first symbol



80
81
82
# File 'lib/sugarfree-config.rb', line 80

def method_missing(symbol, *args)
  ConfigIterator.new(values, symbol).next
end

Instance Method Details

#to_hashObject

Returns all the config as a big hash



72
73
74
# File 'lib/sugarfree-config.rb', line 72

def to_hash
  @values
end

#valuesObject



57
58
59
60
# File 'lib/sugarfree-config.rb', line 57

def values
  @values = fetch_config unless @values && !@force_reload
  @values
end