Sha256: 1ff8013bc4c5d0b87ead73ab9473a719ae6ef3c09b8535a5823b3e6c4fe05753

Contents?: true

Size: 1.13 KB

Versions: 31

Compression:

Stored size: 1.13 KB

Contents

require 'rom/pipeline'

module ROM
  module Commands
    # Composite command that consists of left and right commands
    #
    # @api public
    class Composite < Pipeline::Composite
      # Calls the composite command
      #
      # Right command is called with a result from the left one
      #
      # @return [Object]
      #
      # @api public
      def call(*args)
        response = left.call(*args)

        if response.nil? || (many? && response.size == 0)
          return one? ? nil : EMPTY_ARRAY
        end

        if one? && !graph?
          if right.is_a?(Command) || right.is_a?(Commands::Composite)
            right.call([response].first)
          else
            right.call([response]).first
          end
        elsif one? && graph?
          right.call(response).first
        else
          right.call(response)
        end
      end
      alias_method :[], :call

      # @api private
      def graph?
        left.is_a?(Graph)
      end

      # @api private
      def result
        left.result
      end

      # @api private
      def decorate?(response)
        super || response.is_a?(Graph)
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
rom-core-4.2.1 lib/rom/commands/composite.rb
rom-core-4.2.0 lib/rom/commands/composite.rb
rom-core-4.1.2 lib/rom/commands/composite.rb
rom-core-4.1.1 lib/rom/commands/composite.rb
rom-core-4.1.0 lib/rom/commands/composite.rb
rom-core-4.0.2 lib/rom/commands/composite.rb
rom-core-4.0.1 lib/rom/commands/composite.rb
rom-3.3.3 lib/rom/commands/composite.rb
rom-core-4.0.0 lib/rom/commands/composite.rb
rom-3.3.2 lib/rom/commands/composite.rb
rom-core-4.0.0.rc2 lib/rom/commands/composite.rb
rom-core-4.0.0.rc1 lib/rom/commands/composite.rb
rom-core-4.0.0.beta3 lib/rom/commands/composite.rb
rom-3.3.1 lib/rom/commands/composite.rb
rom-core-4.0.0.beta2 lib/rom/commands/composite.rb
rom-3.3.0 lib/rom/commands/composite.rb
rom-core-4.0.0.beta1 lib/rom/commands/composite.rb
rom-3.2.3 lib/rom/commands/composite.rb
rom-3.2.2 lib/rom/commands/composite.rb
rom-3.2.1 lib/rom/commands/composite.rb