Class: Configuration
- Defined in:
- lib/madvertise/configuration.rb
Overview
The Configuration class provides a simple interface to configuration stored inside of YAML files.
Constant Summary collapse
- DEFAULTS =
{ log_backend: :stdout, log_caller: false, log_format: "%{time} %{progname}(%{pid}) [%{severity}] %{msg}\n", log4j_format: "%d %c(%t) [%p] %m%n", log_level: :info, }
Instance Method Summary collapse
-
#callback(&block) ⇒ void
Register a callback for config mixins.
-
#initialize {|config| ... } ⇒ Configuration
constructor
Create a new Configuration object.
-
#mixin(value) ⇒ void
Mixin a configuration snippet into the current section.
-
#reload! ⇒ void
Reload all mixins.
Methods inherited from Section
Methods inherited from Hash
#deep_merge, #deep_merge!, #delta_merge!
Constructor Details
#initialize {|config| ... } ⇒ Configuration
Create a new Configuration object.
93 94 95 96 97 |
# File 'lib/madvertise/configuration.rb', line 93 def initialize @mixins = OrderedSet.new @callbacks = [] mixin(DEFAULTS) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Section
Instance Method Details
#callback(&block) ⇒ void
This method returns an undefined value.
Register a callback for config mixins.
144 145 146 |
# File 'lib/madvertise/configuration.rb', line 144 def callback(&block) @callbacks << block end |
#mixin(value) ⇒ void
This method returns an undefined value.
Mixin a configuration snippet into the current section.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/madvertise/configuration.rb', line 106 def mixin(value) @mixins << value if value.is_a?(String) value = YAML.load(File.read(value)) end return unless value value = Section.from_hash(value) deep_merge!(value[:generic]) if value.has_key?(:generic) if value.has_key?(Env.to_sym) deep_merge!(value[Env.to_sym]) else deep_merge!(value) end end |
#reload! ⇒ void
This method returns an undefined value.
Reload all mixins.
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/madvertise/configuration.rb', line 129 def reload! clear @mixins.each do |file| mixin(file) end @callbacks.each do |callback| callback.call(self) end end |