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
-
#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
- #respond_to_missing_handler(name, include_all) ⇒ Object
Instance Attribute Details
permalink #config_file ⇒ Object
Returns the value of attribute config_file.
6 7 8 |
# File 'lib/config_module/config_helper.rb', line 6 def config_file @config_file end |
permalink #namespaces ⇒ Object
58 59 60 |
# File 'lib/config_module/config_helper.rb', line 58 def namespaces @namespaces ||= [] end |
permalink #raw_config ⇒ Object (readonly)
Returns the value of attribute raw_config.
5 6 7 |
# File 'lib/config_module/config_helper.rb', line 5 def raw_config @raw_config end |
Instance Method Details
permalink #config ⇒ Object
[View source]
9 10 11 |
# File 'lib/config_module/config_helper.rb', line 9 def config @config ||= ConfigOption.wrap load_config end |
permalink #field_lookup_handler(name, _source, *_args, &_block) ⇒ Object
[View source]
28 29 30 |
# File 'lib/config_module/config_helper.rb', line 28 def field_lookup_handler name, _source, *_args, &_block config[name] end |
permalink #load_config ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/config_module/config_helper.rb', line 32 def load_config raise ConfigModule::ConfigFileNotSpecified, config_file unless config_file raise ConfigModule::ConfigFileNotFound, config_file unless File.exist? config_file yaml_load load_namespaces_from raw_config end |
permalink #load_namespaces_from(tree) ⇒ Object
[View source]
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/config_module/config_helper.rb', line 40 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 raise( InvalidNamespaceError.new(namespaces.first, self, caller), "Namespace must be a string or symbol, instead it was: #{namespaces.first.class}", caller(6) ) end |
permalink #method_missing_handler(name, source, *args, &block) ⇒ Object
[View source]
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/config_module/config_helper.rb', line 13 def method_missing_handler name, source, *args, &block ConfigOption.wrap config.send(name, *args, &block) rescue NoMethodError => error raise unless error.name == name raise( ConfigOption::NotFoundError.new(name, self, error), error., source ) end |
permalink #respond_to_missing_handler(name, include_all) ⇒ Object
[View source]
24 25 26 |
# File 'lib/config_module/config_helper.rb', line 24 def respond_to_missing_handler name, include_all config.send(:respond_to_missing?, name, include_all) end |