Sha256: 9f698a8c08da3516f0a272c50a223b9a6d72c204e341738d59aa7d3af85896ec

Contents?: true

Size: 1.16 KB

Versions: 9

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

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.empty?)
          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

9 entries across 9 versions & 1 rubygems

Version Path
rom-core-5.3.2 lib/rom/commands/composite.rb
rom-core-5.3.1 lib/rom/commands/composite.rb
rom-core-5.3.0 lib/rom/commands/composite.rb
rom-core-5.2.6 lib/rom/commands/composite.rb
rom-core-5.2.5 lib/rom/commands/composite.rb
rom-core-5.2.4 lib/rom/commands/composite.rb
rom-core-5.2.3 lib/rom/commands/composite.rb
rom-core-5.2.2 lib/rom/commands/composite.rb
rom-core-5.2.1 lib/rom/commands/composite.rb