Module: Startback::Support::TransactionPolicy
- Included in:
- Operation
- Defined in:
- lib/startback/support/transaction_policy.rb
Instance Method Summary collapse
- #after_commit(&bl) ⇒ Object
-
#transaction_policy ⇒ Object
Returns the operation’s transaction policy.
-
#transaction_policy=(policy) ⇒ Object
Sets the transaction policy to use.
Instance Method Details
#after_commit(&bl) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/startback/support/transaction_policy.rb', line 23 def after_commit(&bl) after_call do db.after_commit do instance_exec(&bl) end end end |
#transaction_policy ⇒ Object
Returns the operation’s transaction policy
6 7 8 |
# File 'lib/startback/support/transaction_policy.rb', line 6 def transaction_policy @transaction_policy || :before_call end |
#transaction_policy=(policy) ⇒ Object
Sets the transaction policy to use. Valid values are:
-
before_call : the transaction is started by the operation runner, right before calling the #call method on operation instance
-
within_call: the transaction is started by the operation itself, as part of its internal logic.
16 17 18 19 20 21 |
# File 'lib/startback/support/transaction_policy.rb', line 16 def transaction_policy=(policy) unless [:before_call, :within_call].include?(policy) raise ArgumentError, "Unknown policy `#{policy}`" end @transaction_policy = policy end |