Class: ConfigLogic
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ConfigLogic
- Extended by:
- Forwardable
- Includes:
- Logger
- Defined in:
- lib/config_logic.rb,
lib/config_logic/config_logic.rb
Defined Under Namespace
Modules: Logger Classes: Cache, FileCache, Log, LogicElement, Multiplexer, Overlay, TreeCache
Constant Summary
Constants included from Logger::Colors
Logger::Colors::BLUE, Logger::Colors::GREEN, Logger::Colors::RED, Logger::Colors::RESET, Logger::Colors::YELLOW
Instance Method Summary collapse
- #[](*keys) ⇒ Object
-
#initialize(load_paths, params = {}) ⇒ ConfigLogic
constructor
A new instance of ConfigLogic.
Methods included from Logger
Constructor Details
#initialize(load_paths, params = {}) ⇒ ConfigLogic
Returns a new instance of ConfigLogic.
7 8 9 10 11 12 |
# File 'lib/config_logic/config_logic.rb', line 7 def initialize(load_paths, params = {}) @cache = TreeCache.new(load_paths, params) @path = params[:path] || [] @data = @cache[*@path] super(@data) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *args) ⇒ Object (private)
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/config_logic/config_logic.rb', line 40 def method_missing(method_symbol, *args) method_name = method_symbol.to_s element_matcher = ConfigLogic::LogicElement.available_elements.join('|') if (val = self[method_symbol]) val elsif /^insert_(#{element_matcher})$/ === method_name type = ConfigLogic::LogicElement.name_to_type($1) @cache.insert_logic_element(type.new(args.first), @data) if type else super end end |
Instance Method Details
#[](*keys) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/config_logic/config_logic.rb', line 14 def [](*keys) new_path = @path + keys val = @cache[*new_path] case val when Hash self.clone_with_new_path(new_path) when ConfigLogic::LogicElement val.output else val end end |