Class: Cfer::Config
Constant Summary
Constants inherited from BlockHash
BlockHash::NON_PROXIED_METHODS
Instance Method Summary collapse
-
#include_config(*files) ⇒ Object
Includes config code from one or more files, and evals it in the context of this stack.
-
#initialize(file = nil, options = nil, &block) ⇒ Config
constructor
A new instance of Config.
- #method_missing(method_sym, *arguments, &block) ⇒ Object
Methods inherited from BlockHash
#get_property, #properties, #respond_to?
Methods inherited from Block
#build_from_block, #build_from_file, #build_from_string, #include_file, #post_block, #pre_block
Constructor Details
#initialize(file = nil, options = nil, &block) ⇒ Config
Returns a new instance of Config.
3 4 5 6 7 |
# File 'lib/cfer/config.rb', line 3 def initialize(file = nil, = nil, &block) @config_file = file deep_merge! if instance_eval &block if block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cfer/config.rb', line 9 def method_missing(method_sym, *arguments, &block) key = camelize_property(method_sym) case arguments.size when 0 if block Config.new(@config_file, nil, &block) else val = self[key] val = case val when Hash, nil Config.new(nil, val) else val end properties key => val val end else super end end |
Instance Method Details
#include_config(*files) ⇒ Object
Includes config code from one or more files, and evals it in the context of this stack. Filenames are relative to the file containing the invocation of this method.
34 35 36 37 38 39 40 |
# File 'lib/cfer/config.rb', line 34 def include_config(*files) include_base = File.dirname(@config_file) if @config_file files.each do |file| path = File.join(include_base, file) if include_base include_file(path || file) end end |