Sha256: c74a867ba865cf92159ea5b294342d65ba2192403941c4427ab6dcf6961f146f

Contents?: true

Size: 568 Bytes

Versions: 2

Compression:

Stored size: 568 Bytes

Contents

module Yrpc
  module Interceptors
    module ActiveRecord
      class ResetConnection

        def invoke
          if enabled? && !::ActiveRecord::Base.connection.active?
            ::ActiveRecord::Base.establish_connection
          end
          yield
        ensure
          ::ActiveRecord::Base.clear_active_connections! if enabled?
        end

        private

        ##
        # @return [Boolean] If AR is loaded, we can enable this hook safely
        #
        def enabled?
          defined?(::ActiveRecord::Base)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ampedxx-yrpc-0.1.6 lib/yrpc/interceptors/active_record.rb
ampedxx-yrpc-0.1.4 lib/yrpc/interceptors/active_record.rb