Module: SimpleAction::Transactable

Extended by:
ActiveSupport::Concern
Included in:
Service
Defined in:
lib/simple_action/concerns/transactable.rb

Instance Method Summary collapse

Instance Method Details

#transaction { ... } ⇒ Object

Yields:



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/simple_action/concerns/transactable.rb', line 23

def transaction
  return unless block_given?

  if transaction?
    ActiveRecord::Base.transaction(transaction_options) do
      yield
    end
  else
    yield
  end
end

#transaction=(bool) ⇒ Object



35
36
37
# File 'lib/simple_action/concerns/transactable.rb', line 35

def transaction=(bool)
  @@transaction = !!bool
end

#transaction?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/simple_action/concerns/transactable.rb', line 40

def transaction?
  defined?(@@transaction) ? @@transaction : true
end

#transaction_optionsHash

Returns:

  • (Hash)


45
46
47
# File 'lib/simple_action/concerns/transactable.rb', line 45

def transaction_options
  {}
end