Sha256: 9757ae82669b2ea7a4346462ba5e298ee3b0e22f80e41ce3715beaf105b16576

Contents?: true

Size: 1.16 KB

Versions: 10

Compression:

Stored size: 1.16 KB

Contents

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 & 1 rubygems

Version Path
rom-core-4.2.1 lib/rom/commands/lazy/update.rb
rom-core-4.2.0 lib/rom/commands/lazy/update.rb
rom-core-4.1.2 lib/rom/commands/lazy/update.rb
rom-core-4.1.1 lib/rom/commands/lazy/update.rb
rom-core-4.1.0 lib/rom/commands/lazy/update.rb
rom-core-4.0.2 lib/rom/commands/lazy/update.rb
rom-core-4.0.1 lib/rom/commands/lazy/update.rb
rom-core-4.0.0 lib/rom/commands/lazy/update.rb
rom-core-4.0.0.rc2 lib/rom/commands/lazy/update.rb
rom-core-4.0.0.rc1 lib/rom/commands/lazy/update.rb