Module: Leftovers::ProcessorBuilders::Action

Defined in:
lib/leftovers/processor_builders/action.rb

Class Method Summary collapse

Class Method Details

.build(patterns, final_processor) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/leftovers/processor_builders/action.rb', line 7

def build(patterns, final_processor)
  Each.each_or_self(patterns) do |pattern|
    case pattern
    when ::String, ::Integer then Argument.build(pattern, final_processor)
    when ::Hash then build_from_hash_value(**pattern, final_processor: final_processor)
    # :nocov:
    else raise UnexpectedCase, "Unhandled value #{pattern.inspect}"
      # :nocov:
    end
  end
end

.build_from_hash_value(final_processor:, arguments: nil, keywords: nil, itself: nil, receiver: nil, value: nil, nested: nil, recursive: nil, has_arguments: nil, has_receiver: nil, unless_arg: nil, all: nil, any: nil, **transform_args) ⇒ Object

rubocop:disable Metrics/ParameterLists



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/leftovers/processor_builders/action.rb', line 19

def build_from_hash_value( # rubocop:disable Metrics/ParameterLists
  final_processor:,
  arguments: nil,
  keywords: nil,
  itself: nil,
  receiver: nil,
  value: nil,
  nested: nil,
  recursive: nil,

  has_arguments: nil,
  has_receiver: nil,
  unless_arg: nil, all: nil, any: nil,
  **transform_args
)
  processor = TransformSet.build(
    transform_args, final_processor
  )
  processor = build_nested(nested, processor) if nested
  recursive_placeholder, processor = build_recursive(processor) if recursive
  processor = build_sources(arguments, keywords, itself, receiver, value, processor)
  processor = build_matcher(has_arguments, has_receiver, unless_arg, all, any, processor)
  return processor unless recursive

  recursive_placeholder.processor = processor
  recursive_placeholder
end