Sha256: c2fd631a71f6085402a88319178bcfba02276087178036c18a757c6c389002b3

Contents?: true

Size: 859 Bytes

Versions: 10

Compression:

Stored size: 859 Bytes

Contents

# frozen_string_literal: true

module ROM
  module Commands
    class Lazy
      # Lazy command wrapper for create commands
      #
      # @api public
      class Create < Lazy
        # Execute a command
        #
        # @see Command::Create#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)
              command_proc[command, parent, children].call(children, parent)
            end.reduce(:concat)
          else
            input = evaluator.call(first)
            command.call(input, *args[1..size - 1])
          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/create.rb
rom-core-5.3.1 lib/rom/commands/lazy/create.rb
rom-core-5.3.0 lib/rom/commands/lazy/create.rb
rom-6.0.0.alpha1 lib/rom/commands/lazy/create.rb
rom-core-5.2.6 lib/rom/commands/lazy/create.rb
rom-core-5.2.5 lib/rom/commands/lazy/create.rb
rom-core-5.2.4 lib/rom/commands/lazy/create.rb
rom-core-5.2.3 lib/rom/commands/lazy/create.rb
rom-core-5.2.2 lib/rom/commands/lazy/create.rb
rom-core-5.2.1 lib/rom/commands/lazy/create.rb