Class: ActiveRecord::SaferMigrations::SettingHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/safer_migrations/setting_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection, setting_name, value) ⇒ SettingHelper

Returns a new instance of SettingHelper.



6
7
8
9
10
# File 'lib/active_record/safer_migrations/setting_helper.rb', line 6

def initialize(connection, setting_name, value)
  @connection = connection
  @setting_name = setting_name
  @value = value
end

Instance Method Details

#with_settingObject

We’re changing a connection level setting, and we need to make sure we return it to the original value. It is automatically reverted if set within a transaction which rolls back, so that case needs handling differently.

| In Transaction      | Not in transaction

Raises | Reset setting | Reset setting Doesn’t raise | Don’t reset setting | Reset setting



20
21
22
23
24
25
26
27
28
# File 'lib/active_record/safer_migrations/setting_helper.rb', line 20

def with_setting
  record_current_setting
  set_new_setting
  yield
  reset_setting
rescue StandardError
  reset_setting unless in_transaction?
  raise
end