Sha256: 5a0d4379a65e8f537efb976c0c7880fa70847d6c04d5facbf3009ff969304df5

Contents?: true

Size: 1.14 KB

Versions: 8

Compression:

Stored size: 1.14 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_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

8 entries across 8 versions & 1 rubygems

Version Path
rom-core-4.1.2 lib/rom/relation/wrap.rb
rom-core-4.1.1 lib/rom/relation/wrap.rb
rom-core-4.1.0 lib/rom/relation/wrap.rb
rom-core-4.0.2 lib/rom/relation/wrap.rb
rom-core-4.0.1 lib/rom/relation/wrap.rb
rom-core-4.0.0 lib/rom/relation/wrap.rb
rom-core-4.0.0.rc2 lib/rom/relation/wrap.rb
rom-core-4.0.0.rc1 lib/rom/relation/wrap.rb