Sha256: a223b4678a4e709fe97b222bab5cc73493f73eb78db3d320b6089967354d0da5

Contents?: true

Size: 1.39 KB

Versions: 5

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

class PGTrunk::Operation
  # @private
  # Invoke all the necessary definitions
  # in the modules included to Rails via Railtie
  module Registration
    extend ActiveSupport::Concern

    class_methods do
      def from_sql(&block)
        super.tap { register_dumper if block }
      end

      def generates_object(name = nil)
        super.tap { register_generator if name }
      end

      def method_added(name)
        super
      ensure
        register_operation if name == :to_sql
        register_inversion if name == :invert
      end

      private

      def register_operation
        # Add the method to statements as an entry point
        PGTrunk::Statements.register(self)
        # Add the shortcut to migration go get away with checking
        # of the first parameter which could be NOT a table name.
        PGTrunk::Migration.register(self)
        # Record the direct operation
        PGTrunk::CommandRecorder.register(self)
      end

      def register_inversion
        # Record the inversion of the operation
        PGTrunk::CommandRecorder.register_inversion(self)
      end

      def register_dumper
        PGTrunk::SchemaDumper.register(self)
      end

      def register_generator
        # skip registration in the runtime
        return unless const_defined?("PGTrunk::Generators")

        PGTrunk::Generators.register(self)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pg_trunk-0.2.0 lib/pg_trunk/core/operation/registration.rb
pg_trunk-0.1.3 lib/pg_trunk/core/operation/registration.rb
pg_trunk-0.1.2 lib/pg_trunk/core/operation/registration.rb
pg_trunk-0.1.1 lib/pg_trunk/core/operation/registration.rb
pg_trunk-0.1.0 lib/pg_trunk/core/operation/registration.rb