Class: Dry::Effects::Providers::Lock
- Inherits:
-
Object
- Object
- Dry::Effects::Providers::Lock
- Defined in:
- lib/dry/effects/providers/lock.rb
Defined Under Namespace
Constant Summary collapse
- Locate =
Effect.new(type: :lock, name: :locate)
Instance Method Summary collapse
-
#call(backend = Undefined) ⇒ Object
private
Yield the block with the handler installed.
-
#locate ⇒ Provider
private
Locate handler in the stack.
- #lock(key, meta = Undefined) ⇒ Object
- #locked?(key) ⇒ Boolean
- #meta(key) ⇒ Object
- #owned ⇒ Object
- #represent ⇒ Object
- #unlock(handle) ⇒ Object
- #with_backend(backend) ⇒ Object
Instance Method Details
#call(backend = Undefined) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Yield the block with the handler installed
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dry/effects/providers/lock.rb', line 78 def call(backend = Undefined) backend_replace = Undefined.default(backend) do parent = ::Dry::Effects.yield(Locate) { Undefined } Undefined.map(parent, &:backend) end with_backend(backend_replace) do yield ensure owned.each { unlock(_1) } end end |
#locate ⇒ Provider
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Locate handler in the stack
73 |
# File 'lib/dry/effects/providers/lock.rb', line 73 def locate = self |
#lock(key, meta = Undefined) ⇒ Object
57 58 59 60 61 |
# File 'lib/dry/effects/providers/lock.rb', line 57 def lock(key, = Undefined) locked = backend.lock(key, ) owned << locked if locked locked end |
#locked?(key) ⇒ Boolean
63 |
# File 'lib/dry/effects/providers/lock.rb', line 63 def locked?(key) = backend.locked?(key) |
#meta(key) ⇒ Object
67 |
# File 'lib/dry/effects/providers/lock.rb', line 67 def (key) = backend.(key) |
#owned ⇒ Object
104 105 106 |
# File 'lib/dry/effects/providers/lock.rb', line 104 def owned @owned ||= [] end |
#represent ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/dry/effects/providers/lock.rb', line 108 def represent if owned.empty? super else "lock[owned=#{owned.size}]" end end |
#unlock(handle) ⇒ Object
65 |
# File 'lib/dry/effects/providers/lock.rb', line 65 def unlock(handle) = backend.unlock(handle) |
#with_backend(backend) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/dry/effects/providers/lock.rb', line 91 def with_backend(backend) if Undefined.equal?(backend) yield else begin before, @backend = @backend, backend yield ensure @backend = before end end end |