Sha256: 94fd51839fc65a4e8ba799c64859ac869cb30885171655469dae77f6f86e01e5

Contents?: true

Size: 984 Bytes

Versions: 5

Compression:

Stored size: 984 Bytes

Contents

module ROM
  module Commands
    # Composite command that consists of left and right commands
    #
    # @api public
    class Composite
      include Equalizer.new(:left, :right)

      # @return [Proc,Command] left command
      #
      # @api private
      attr_reader :left

      # @return [Proc,Command] right command
      #
      # @api private
      attr_reader :right

      # @api private
      def initialize(left, right)
        @left, @right = left, right
      end

      # Calls the composite command
      #
      # Right command is called with a result from the left one
      #
      # @return [Object]
      #
      # @api public
      def call(*args)
        right.call(left.call(*args))
      end

      # Compose another composite command from self and other
      #
      # @param [Proc, Command] other command
      #
      # @return [Composite]
      #
      # @api public
      def >>(other)
        self.class.new(self, other)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rom-0.6.0 lib/rom/commands/composite.rb
rom-0.6.0.rc1 lib/rom/commands/composite.rb
rom-0.6.0.beta3 lib/rom/commands/composite.rb
rom-0.6.0.beta2 lib/rom/commands/composite.rb
rom-0.6.0.beta1 lib/rom/commands/composite.rb