Class: Synapse::UnitOfWork::UnitOfWorkProvider
- Inherits:
-
Object
- Object
- Synapse::UnitOfWork::UnitOfWorkProvider
- Defined in:
- lib/synapse/uow/provider.rb
Overview
Entry point for components to access units of work. Components managing transactional boundaries can register and clear unit of work instances.
Instance Method Summary collapse
-
#clear(unit) ⇒ undefined
Clears the given unit of work from this provider.
-
#commit ⇒ undefined
Commits the current unit of work.
-
#current ⇒ UnitOfWork
Returns the current unit of work if one is set.
-
#initialize ⇒ UnitOfWorkProvider
constructor
A new instance of UnitOfWorkProvider.
-
#push(unit) ⇒ undefined
Pushes the given unit of work onto the top of the stack, making it the active unit of work.
-
#started? ⇒ Boolean
Returns true if there is an active unit of work.
Constructor Details
#initialize ⇒ UnitOfWorkProvider
Returns a new instance of UnitOfWorkProvider.
6 7 8 |
# File 'lib/synapse/uow/provider.rb', line 6 def initialize @threads = Hash.new end |
Instance Method Details
#clear(unit) ⇒ undefined
Clears the given unit of work from this provider
If the given unit of work is not known to the provider, or it is not the active unit of work, then this method will raise an exception.
17 18 19 20 21 22 23 |
# File 'lib/synapse/uow/provider.rb', line 17 def clear(unit) unless stack.last == unit raise ArgumentError, 'The given unit of work is not the active unit of work' end stack.pop end |
#commit ⇒ undefined
Commits the current unit of work
27 28 29 |
# File 'lib/synapse/uow/provider.rb', line 27 def commit current.commit end |
#current ⇒ UnitOfWork
Returns the current unit of work if one is set
35 36 37 38 39 40 41 |
# File 'lib/synapse/uow/provider.rb', line 35 def current if stack.empty? raise 'No unit of work is active' end stack.last end |
#push(unit) ⇒ undefined
Pushes the given unit of work onto the top of the stack, making it the active unit of work
If there are other units of work bound to this provider, they will be held until the given unit of work is cleared.
51 52 53 |
# File 'lib/synapse/uow/provider.rb', line 51 def push(unit) stack.push unit end |
#started? ⇒ Boolean
Returns true if there is an active unit of work
57 58 59 |
# File 'lib/synapse/uow/provider.rb', line 57 def started? !stack.empty? end |