Sha256: decb5dfbf22fc4d994152018e9428efa08cb00164833593f07d88c64ef8d5fc6

Contents?: true

Size: 1.04 KB

Versions: 10

Compression:

Stored size: 1.04 KB

Contents

module Micronaut
  module Rails
    module TransactionalDatabaseSupport

      module InstanceMethods

        def active_record_configured?
          defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank?
        end

        def transactional_protection_start
          return unless active_record_configured?

          ActiveRecord::Base.connection.increment_open_transactions
          ActiveRecord::Base.connection.begin_db_transaction
        end

        def transactional_protection_cleanup
          return unless active_record_configured?

          if ActiveRecord::Base.connection.open_transactions != 0
            ActiveRecord::Base.connection.rollback_db_transaction
            ActiveRecord::Base.connection.decrement_open_transactions
          end

          ActiveRecord::Base.clear_active_connections!
        end

      end

      def self.extended(kls)
        kls.send(:include, InstanceMethods)
        kls.before { transactional_protection_start }
        kls.after { transactional_protection_cleanup }
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
spicycode-micronaut-rails-0.0.6.1 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.0.6.2 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.1.7.0 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.1.7.1 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.1.8.0 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.1.8.1 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.1.9.0 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.2.0.0 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.2.2 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.2.3 lib/micronaut/rails/transactional_database_support.rb