Sha256: 2251494a0b7a20d93cae772629f08d336034d45e869c580e71e6b39a4f66292b

Contents?: true

Size: 1.19 KB

Versions: 1

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

1 entries across 1 versions & 1 rubygems

Version Path
rom-6.0.0.alpha1 lib/rom/relation/wrap.rb