Sha256: 3ce48abb54d021724e4def35422f5683112a3a3ab127f1f0ca330cc6b55a65a4

Contents?: true

Size: 1.62 KB

Versions: 6

Compression:

Stored size: 1.62 KB

Contents

module ROM
  module Plugins
    module Relation
      module SQL
        # @api private
        module AutoWrap
          # @api private
          def self.included(klass)
            super
            klass.class_eval do
              include(InstanceInterface)
              extend(ClassInterface)
            end
          end

          # @api private
          module ClassInterface
            # @api private
            def inherited(klass)
              super
              klass.auto_curry :for_wrap
            end
          end

          # @api private
          module InstanceInterface
            # Default methods for fetching wrapped relation
            #
            # This method is used by default by `wrap` and `wrap_parents`
            #
            # @return [SQL::Relation]
            #
            # @api private
            def for_wrap(keys, name)
              rel, other =
                if associations.key?(name)
                  assoc = associations[name]
                  other = __registry__[assoc.target.relation]

                  [assoc.join(__registry__, :inner_join, self, other), other]
                else
                  # TODO: deprecate this before 2.0
                  other = __registry__[name]
                  other_dataset = other.name.dataset

                  [qualified.inner_join(other_dataset, keys), other]
                end

              rel.schema.merge(other.schema.wrap).qualified.(rel)
            end
          end
        end
      end
    end
  end
end

ROM.plugins do
  adapter :sql do
    register :auto_wrap, ROM::Plugins::Relation::SQL::AutoWrap, type: :relation
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rom-sql-1.3.5 lib/rom/plugins/relation/sql/auto_wrap.rb
rom-sql-1.3.4 lib/rom/plugins/relation/sql/auto_wrap.rb
rom-sql-1.3.3 lib/rom/plugins/relation/sql/auto_wrap.rb
rom-sql-1.3.2 lib/rom/plugins/relation/sql/auto_wrap.rb
rom-sql-1.3.1 lib/rom/plugins/relation/sql/auto_wrap.rb
rom-sql-1.3.0 lib/rom/plugins/relation/sql/auto_wrap.rb