Module: Hyperactive::Transactions::Participant
- Included in:
- Record::Bass
- Defined in:
- lib/hyperactive/transactions.rb
Overview
Include this to get methods to do with participating in a transaction.
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#transaction ⇒ Object
readonly
The transaction we are currently in.
Class Method Summary collapse
-
.append_features(base) ⇒ Object
Add our ClassMethods to anyone that includes us.
Instance Method Summary collapse
-
#with_transaction(transaction, &block) ⇒ Object
Will execute
blockwithin a transaction.
Instance Attribute Details
#transaction ⇒ Object (readonly)
The transaction we are currently in.
33 34 35 |
# File 'lib/hyperactive/transactions.rb', line 33 def transaction @transaction end |
Class Method Details
.append_features(base) ⇒ Object
Add our ClassMethods to anyone that includes us.
62 63 64 65 |
# File 'lib/hyperactive/transactions.rb', line 62 def self.append_features(base) super base.extend(ClassMethods) end |
Instance Method Details
#with_transaction(transaction, &block) ⇒ Object
Will execute block within a transaction.
What it does is just set the @transaction instance variable before calling the block, and unsetting it after.
This means that any classes that want to be transaction sensitive need to take heed regarding the @transaction instance variable.
For example, when creating new Record instances you may want to use get_instance_with_transaction(@transaction, *args) to ensure that the new instance exists within the same transaction as yourself.
See Hyperactive::List::Head and Hyperactive::Hash::Head for examples of this behaviour.
50 51 52 53 54 55 56 57 |
# File 'lib/hyperactive/transactions.rb', line 50 def with_transaction(transaction, &block) @transaction = transaction begin yield ensure @transaction = nil end end |