Class: SmartConfig::Walker

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_config/walker.rb

Overview

Loads the data from any configured source and walks through it to find values

Instance Method Summary collapse

Constructor Details

#initialize(sources) ⇒ Walker

Returns a new instance of Walker.



11
12
13
# File 'lib/smart_config/walker.rb', line 11

def initialize(sources)
  @sources = sources
end

Instance Method Details

#walk(path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/smart_config/walker.rb', line 15

def walk(path)
  data.filter_map do |d|
    next if d[:data].nil?

    case d[:strategy]
    when :nested
      d[:data].dig(*path.split('.'))
    when :flat
      d[:data][path.tr('.', '_')]
    end
  end
end