Sha256: b213d774f102d3d1776c6bcdbe674727d4b8f1cbbf25b1984c5d3f717cd45ca6

Contents?: true

Size: 1.19 KB

Versions: 10

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module ROM
  module Commands
    class Lazy
      # Lazy command wrapper for update commands
      #
      # @api public
      class Update < Lazy
        # Execute a lazy update command
        #
        # @see Commands::Update#call
        #
        # @return [Hash, Array<Hash>]
        #
        # @api public
        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
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
rom-core-5.3.2 lib/rom/commands/lazy/update.rb
rom-core-5.3.1 lib/rom/commands/lazy/update.rb
rom-core-5.3.0 lib/rom/commands/lazy/update.rb
rom-6.0.0.alpha1 lib/rom/commands/lazy/update.rb
rom-core-5.2.6 lib/rom/commands/lazy/update.rb
rom-core-5.2.5 lib/rom/commands/lazy/update.rb
rom-core-5.2.4 lib/rom/commands/lazy/update.rb
rom-core-5.2.3 lib/rom/commands/lazy/update.rb
rom-core-5.2.2 lib/rom/commands/lazy/update.rb
rom-core-5.2.1 lib/rom/commands/lazy/update.rb