Sha256: 92979dc9cd56ff9d33ff63b959f37c269234daf7baf1d88e7008605237279000

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

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

2 entries across 2 versions & 1 rubygems

Version Path
rom-core-4.2.1 lib/rom/relation/wrap.rb
rom-core-4.2.0 lib/rom/relation/wrap.rb