Class: ROM::Commands::Lazy::Update

Inherits:
ROM::Commands::Lazy show all
Defined in:
lib/rom/commands/lazy/update.rb

Overview

Lazy command wrapper for update commands

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from ROM::Commands::Lazy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ROM::Commands::Lazy

Instance Method Details

#call(*args) ⇒ Hash+

Execute a lazy update command

Returns:

  • (Hash, Array<Hash>)

See Also:

  • Commands::Update#call

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rom/commands/lazy/update.rb', line 17

def call(*args)
  first = args.first
  last = args.last
  size = args.size

  if size > 1 && last.is_a?(Array)
    last.map.with_index do |parent, index|
      children = evaluator.call(first, index)

      children.map do |child|
        command_proc[command, parent, child].call(child, parent)
      end
    end.reduce(:concat)
  else
    input = evaluator.call(first)

    if input.is_a?(Array)
      input.map.with_index do |item, _index|
        command_proc[command, last, item].call(item, *args[1..size - 1])
      end
    else
      command_proc[command, *(size > 1 ? [last, input] : [input])]
        .call(input, *args[1..size - 1])
    end
  end
end