Module: SaferRailsConsole::Patches::Sandbox::AutoRollback

Defined in:
lib/safer_rails_console/patches/sandbox/auto_rollback.rb

Defined Under Namespace

Modules: LegacyMySQLAdapterRails67Patch, LegacyPostgreSQLAdapteRailsPatch, MySQLAdapterRailsPatch, PostgreSQLAdapteRailsPatch

Class Method Summary collapse

Class Method Details

.handle_and_reraise_exception(error, message = 'PG::ReadOnlySqlTransaction') ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/safer_rails_console/patches/sandbox/auto_rollback.rb', line 14

def self.handle_and_reraise_exception(error, message = 'PG::ReadOnlySqlTransaction')
  if error.message.include?(message)
    puts SaferRailsConsole::Colors.color_text( # rubocop:disable Rails/Output
      'An operation could not be completed due to read-only mode.',
      SaferRailsConsole::Colors::RED
    )
  else
    rollback_and_begin_new_transaction
  end

  raise error
end

.rollback_and_begin_new_transactionObject



8
9
10
11
12
# File 'lib/safer_rails_console/patches/sandbox/auto_rollback.rb', line 8

def self.rollback_and_begin_new_transaction
  connection = ::ActiveRecord::Base.connection
  connection.rollback_db_transaction
  connection.begin_db_transaction
end