class ActiveRecord::WrappedTransaction::Context
Attributes
isolation[R]
joinable[R]
parent[R]
@!attribute [r] parent @return [ActiveRecord::WrappedTransaction::Context]
requires_new[R]
transactor[R]
@!attribute [r] transactor @return [#transaction, ActiveRecord::ConnectionAdapters::AbstractAdapter]
Public Class Methods
new(transactor:, requires_new: nil, isolation: nil, joinable: true, parent: nil)
click to toggle source
# File lib/activerecord/wrapped_transaction/context.rb, line 16 def initialize(transactor:, requires_new: nil, isolation: nil, joinable: true, parent: nil) @transactor = TRANSACTOR[transactor] @requires_new = requires_new @isolation = isolation @joinable = joinable @parent = parent @transaction_options = { requires_new: @requires_new, isolation: @isolation, joinable: @joinable }.freeze end
Public Instance Methods
cancel!(reason = nil)
click to toggle source
Cancel the current transaction with an arbitrary `reason`.
@param [String] reason @return [void]
# File lib/activerecord/wrapped_transaction/context.rb, line 54 def cancel!(reason = nil) throw :cancel_transaction, reason end
depth()
click to toggle source
@!attribute [r] depth The depth of the wrapped transaction @return [Integer]
# File lib/activerecord/wrapped_transaction/context.rb, line 33 def depth @depth ||= calculate_depth end
maybe(**new_options, &block)
click to toggle source
@return [ActiveRecord::WrappedContext::Result]
# File lib/activerecord/wrapped_transaction/context.rb, line 38 def maybe(**new_options, &block) new_options[:joinable] = false new_options[:requires_new] = true build_result(**new_options, &block) end
wrap(**new_options, &block)
click to toggle source
@return [ActiveRecord::WrappedContext::Result]
# File lib/activerecord/wrapped_transaction/context.rb, line 46 def wrap(**new_options, &block) build_result(**new_options, &block) end
wrap_transaction() { || ... }
click to toggle source
@api private
# File lib/activerecord/wrapped_transaction/context.rb, line 59 def wrap_transaction transactor.transaction **@transaction_options do yield end end
Private Instance Methods
build_result(**new_options, &block)
click to toggle source
# File lib/activerecord/wrapped_transaction/context.rb, line 67 def build_result(**new_options, &block) options = build_result_options(**new_options) Result.new(**options, &block) end
build_result_options(requires_new: @requires_new, isolation: @isolation, joinable: @joinable, **unused_options)
click to toggle source
# File lib/activerecord/wrapped_transaction/context.rb, line 73 def build_result_options(requires_new: @requires_new, isolation: @isolation, joinable: @joinable, **unused_options) # :nocov: unused_options.each do |key, value| warn "received unused option: #{key.inspect} => #{value.inspect}" end # :nocov: { transactor: @transactor, requires_new: requires_new, isolation: isolation, joinable: joinable, parent_context: self } end
calculate_depth()
click to toggle source
@return [Integer]
# File lib/activerecord/wrapped_transaction/context.rb, line 90 def calculate_depth parent.nil? ? 0 : parent.depth + 1 end