Sha256: 237f66c98ef9b3b9fcba47abbf3ba77604c1e56f37deadb295200fbc3301bcae

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

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

          module ClassInterface
            def inherited(klass)
              super
              klass.auto_curry :for_wrap
            end
          end

          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)
              other = __registry__[name]

              inner_join(name, keys)
                .select(*qualified.header.columns)
                .select_append(*other.prefix(other.name).qualified.header)
            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

4 entries across 4 versions & 2 rubygems

Version Path
rom-sql-0.7.0 lib/rom/plugins/relation/sql/auto_wrap.rb
rom-sql-0.7.0.rc1 lib/rom/plugins/relation/sql/auto_wrap.rb
rom-sql-0.7.0.beta1 lib/rom/plugins/relation/sql/auto_wrap.rb
rom-repository-0.1.0 lib/rom/plugins/relation/sql/auto_wrap.rb