Sha256: ffaed232d9552b03bab12ef652f3632ff874458074da0591b8c951498c3caa94

Contents?: true

Size: 1.07 KB

Versions: 15

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require 'rom/relation/loaded'
require 'rom/relation/materializable'
require 'rom/pipeline'

module ROM
  class Relation
    # Left-to-right relation composition used for data-pipelining
    #
    # @api public
    class Composite < Pipeline::Composite
      include Materializable

      # Call the pipeline by passing results from left to right
      #
      # Optional args are passed to the left object
      #
      # @return [Loaded]
      #
      # @api public
      def call(*args)
        relation = left.call(*args)
        response = right.call(relation)

        if response.is_a?(Loaded)
          response
        else
          relation.new(response)
        end
      end
      alias_method :[], :call

      # @see Relation#map_to
      #
      # @api public
      def map_to(klass)
        self >> left.map_to(klass).mapper
      end

      private

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rom-core-5.3.2 lib/rom/relation/composite.rb
rom-core-5.3.1 lib/rom/relation/composite.rb
rom-core-5.3.0 lib/rom/relation/composite.rb
rom-core-5.2.6 lib/rom/relation/composite.rb
rom-core-5.2.5 lib/rom/relation/composite.rb
rom-core-5.2.4 lib/rom/relation/composite.rb
rom-core-5.2.3 lib/rom/relation/composite.rb
rom-core-5.2.2 lib/rom/relation/composite.rb
rom-core-5.2.1 lib/rom/relation/composite.rb
rom-core-5.1.2 lib/rom/relation/composite.rb
rom-core-5.1.1 lib/rom/relation/composite.rb
rom-core-5.1.0 lib/rom/relation/composite.rb
rom-core-5.0.2 lib/rom/relation/composite.rb
rom-core-5.0.1 lib/rom/relation/composite.rb
rom-core-5.0.0 lib/rom/relation/composite.rb