Sha256: 5e5838d182ca5b31be703a228d367980d0b76849d608fc9235bbe916c94bf640

Contents?: true

Size: 1.19 KB

Versions: 15

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require 'rom/relation/graph'
require 'rom/relation/combined'

module ROM
  class Relation
    # Relation wrapping other relations
    #
    # @api public
    class Wrap < Graph
      # Wrap more relations
      #
      # @see Relation#wrap
      #
      # @return [Wrap]
      #
      # @api public
      def wrap(*args)
        self.class.new(root, nodes + root.wrap(*args).nodes)
      end

      # Materialize a wrap
      #
      # @see Relation#call
      #
      # @return [Loaded]
      #
      # @api public
      def call(*args)
        if auto_map?
          Loaded.new(self, mapper.(relation.with(auto_map: false, auto_struct: false)))
        else
          Loaded.new(self, relation.(*args))
        end
      end

      # Return an adapter-specific relation representing a wrap
      #
      # @abstract
      #
      # @api private
      def relation
        raise NotImplementedError
      end

      # Return if this is a wrap relation
      #
      # @return [true]
      #
      # @api private
      def wrap?
        true
      end

      private

      # @api private
      def decorate?(other)
        super || other.is_a?(Combined)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

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