Class: SmartConfig::Walker
- Inherits:
-
Object
- Object
- SmartConfig::Walker
- Defined in:
- lib/smart_config/walker.rb
Overview
Loads the data from any configured source and walks through it to find values
Class Attribute Summary collapse
-
.strategies ⇒ Object
readonly
Returns the value of attribute strategies.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(sources) ⇒ Walker
constructor
A new instance of Walker.
- #walk(path) ⇒ Object
Constructor Details
#initialize(sources) ⇒ Walker
Returns a new instance of Walker.
24 25 26 |
# File 'lib/smart_config/walker.rb', line 24 def initialize(sources) @sources = sources end |
Class Attribute Details
.strategies ⇒ Object (readonly)
Returns the value of attribute strategies.
17 18 19 |
# File 'lib/smart_config/walker.rb', line 17 def strategies @strategies end |
Class Method Details
.register_strategy(name, &block) ⇒ Object
19 20 21 |
# File 'lib/smart_config/walker.rb', line 19 def register_strategy(name, &block) @strategies[name.to_sym] = block end |
Instance Method Details
#walk(path) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/smart_config/walker.rb', line 28 def walk(path) data.each_with_object([]) do |d, results| next if d[:data].nil? strategy = self.class.strategies.fetch(d[:strategy]) do raise ArgumentError, "Unknown SmartConfig walker strategy: #{d[:strategy].inspect}" end value = strategy.call(d[:data], path) results << value unless value.nil? end end |