Class: Remap::Rule::Block

Inherits:
Unit
  • Object
show all
Defined in:
lib/remap/rule/block.rb

Instance Method Summary collapse

Instance Method Details

#backtraceArray<Rule>

Returns:



9
# File 'lib/remap/rule/block.rb', line 9

attribute :backtrace, [String], min_size: 1

#call(state) ⇒ State

Represents a non-empty define block with one or more rules Calls every #rules with state and merges the output

Parameters:

Returns:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/remap/rule/block.rb', line 18

def call(state)
  init = state.except(:value)

  if rules.empty?
    return init
  end

  catch_fatal(init, backtrace) do |s1, fatal_id:|
    s2 = state.set(fatal_id: fatal_id)

    catch_ignored(s1) do |s3, id:|
      states = rules.map do |rule|
        rule.call(s2)
      end

      states.reduce(s3) do |s4, s5|
        s6 = s5.set(id: id)
        s4.combine(s6)
      end
    end
  end
end