Class: ConfigModule::ConfigHelper
- Inherits:
-
Object
- Object
- ConfigModule::ConfigHelper
- Defined in:
- lib/config_module/config_helper.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#namespaces ⇒ Object
Returns the value of attribute namespaces.
-
#raw_config ⇒ Object
readonly
Returns the value of attribute raw_config.
Instance Method Summary collapse
- #config ⇒ Object
- #field_lookup_handler(name, source, *args, &block) ⇒ Object
- #load_config ⇒ Object
- #load_namespaces_from(tree) ⇒ Object
- #method_missing_handler(name, source, *args, &block) ⇒ Object
Instance Attribute Details
#config_file ⇒ Object
Returns the value of attribute config_file.
4 5 6 |
# File 'lib/config_module/config_helper.rb', line 4 def config_file @config_file end |
#namespaces ⇒ Object
Returns the value of attribute namespaces.
4 5 6 |
# File 'lib/config_module/config_helper.rb', line 4 def namespaces @namespaces end |
#raw_config ⇒ Object (readonly)
Returns the value of attribute raw_config.
3 4 5 |
# File 'lib/config_module/config_helper.rb', line 3 def raw_config @raw_config end |
Instance Method Details
#config ⇒ Object
6 7 8 |
# File 'lib/config_module/config_helper.rb', line 6 def config @config ||= ConfigOption.wrap load_config end |
#field_lookup_handler(name, source, *args, &block) ⇒ Object
23 24 25 |
# File 'lib/config_module/config_helper.rb', line 23 def field_lookup_handler name, source, *args, &block config[name] end |
#load_config ⇒ Object
27 28 29 30 31 |
# File 'lib/config_module/config_helper.rb', line 27 def load_config @raw_config = YAML.load_file config_file load_namespaces_from raw_config end |
#load_namespaces_from(tree) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/config_module/config_helper.rb', line 33 def load_namespaces_from tree namespaces.inject(ConfigOption.wrap tree) do |subtree, ns| if ConfigOption === subtree && ns.respond_to?(:to_sym) && subtree.has_key?(ns) ConfigOption.wrap subtree[ns] else raise( InvalidNamespaceError.new(ns, subtree, caller), "No subkey with name: #{ns.inspect}", caller(6) ) end end rescue TypeError => error raise( InvalidNamespaceError.new(namespaces.first, self, caller), "Namespace must be a string or symbol, instead it was: #{namespaces.first.class}", caller(6) ) end |
#method_missing_handler(name, source, *args, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/config_module/config_helper.rb', line 10 def method_missing_handler name, source, *args, &block config.send name, *args, &block rescue NoMethodError => error if error.name == name then raise( ConfigOption::NotFoundError.new(name, self, error), error., source ) else raise end end |