Module: Rollwire
- Defined in:
- lib/rollwire.rb,
lib/rollwire/errors.rb,
lib/rollwire/report.rb,
lib/rollwire/patcher.rb,
lib/rollwire/railtie.rb,
lib/rollwire/version.rb,
lib/rollwire/notifier.rb,
lib/rollwire/configuration.rb,
lib/rollwire/write_counter.rb,
lib/rollwire/outer_location.rb,
lib/rollwire/execution_state.rb,
lib/rollwire/patches/database_statements.rb,
lib/rollwire/patches/transaction_manager.rb
Defined Under Namespace
Modules: DatabaseStatementsPatch, ExecutionState, Notifier, OuterLocation, Patcher, TransactionManagerPatch, WriteCounter
Classes: Configuration, ConfigurationError, Error, IgnoredNestedRollback, PatchingError, Railtie, Report
Constant Summary
collapse
- VERSION =
"0.1.0"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
21
22
23
|
# File 'lib/rollwire.rb', line 21
def configuration
@configuration
end
|
Class Method Details
.caller_location ⇒ Object
76
77
78
79
80
|
# File 'lib/rollwire.rb', line 76
def caller_location
locations = caller_locations(2, [configuration.backtrace_lines * 20, 20].max)
location = locations.find { |candidate| application_location?(candidate.path) }
format_location(location)
end
|
23
24
25
26
|
# File 'lib/rollwire.rb', line 23
def configure
yield configuration
configuration
end
|
.disable! ⇒ Object
33
34
35
|
# File 'lib/rollwire.rb', line 33
def disable!
@enabled = false
end
|
.enable! ⇒ Object
28
29
30
31
|
# File 'lib/rollwire.rb', line 28
def enable!
@enabled = true
install!
end
|
.enabled? ⇒ Boolean
37
38
39
|
# File 'lib/rollwire.rb', line 37
def enabled?
@enabled && !suppressed?
end
|
.handle_ignored_rollback(connection:, inner_location:, writes:) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/rollwire.rb', line 61
def handle_ignored_rollback(connection:, inner_location:, writes:)
return if configuration.count_writes && writes < configuration.min_writes
report = Report.new(
inner_location: inner_location,
mode: configuration.mode,
outer_location: OuterLocation.for(connection.current_transaction),
writes: writes
)
return if configuration.ignore_if&.call(report)
Notifier.call(report)
report
end
|
.install! ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/rollwire.rb', line 49
def install!
Patcher.install!
@enabled = true if @enabled.nil?
true
rescue StandardError => e
raise if configuration.strict_patching
@enabled = false
warn_internal_error(e)
false
end
|
.reset_configuration! ⇒ Object
92
93
94
95
|
# File 'lib/rollwire.rb', line 92
def reset_configuration!
@configuration = Configuration.new
@enabled = true
end
|
.suppress ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/rollwire.rb', line 41
def suppress
previous_depth = suppression_depth
ExecutionState.write(:suppression_depth, previous_depth + 1)
yield
ensure
restore_suppression_depth(previous_depth)
end
|
.warn_internal_error(error) ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/rollwire.rb', line 82
def warn_internal_error(error)
message = "[Rollwire] internal error: #{error.class}: #{error.message}"
logger = configuration.logger || rails_logger
logger ? logger.warn(message) : Kernel.warn(message)
rescue StandardError
Kernel.warn(message)
rescue Exception nil
end
|