Class: Liquid::Configuration
- Defined in:
- lib/liquid/configuration.rb
Overview
The Configuration class provides a simple interface to configuration stored inside of YAML files.
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 Liquid::Configuration object.
86 87 88 89 |
# File 'lib/liquid/configuration.rb', line 86 def initialize @mixins = OrderedSet.new @callbacks = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Liquid::Section
Instance Method Details
#callback(&block) ⇒ void
This method returns an undefined value.
Register a callback for config mixins.
136 137 138 |
# File 'lib/liquid/configuration.rb', line 136 def callback(&block) @callbacks << block end |
#mixin(value) ⇒ void
This method returns an undefined value.
Mixin a configuration snippet into the current section.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/liquid/configuration.rb', line 98 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.delete(: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.
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/liquid/configuration.rb', line 121 def reload! clear @mixins.each do |file| mixin(file) end @callbacks.each do |callback| callback.call(self) end end |