Class: StructureWalker::Builder

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

Class Method Summary collapse

Class Method Details

.invoke(proc) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/structure_walker.rb', line 8

def invoke(proc)
  walker = ->(steps, data) do
    return if data.nil?

    if steps.empty?
      result = proc.call(data)
    else
      steps = steps.clone
      step = steps.shift
      type, keys = step.is_a?(Array) ? [step.first, step.last] : [step, nil]
      result = StructureWalker::Stepper.invoke(type).call(data, steps, walker, keys)
    end
    result
  end

  walker
end