Class: ConcurrentPipeline::Pipelines::Processors::Locker
- Inherits:
-
Object
- Object
- ConcurrentPipeline::Pipelines::Processors::Locker
- Defined in:
- lib/concurrent_pipeline/pipelines/processors/locker.rb
Instance Attribute Summary collapse
-
#locks ⇒ Object
readonly
Returns the value of attribute locks.
Instance Method Summary collapse
-
#initialize ⇒ Locker
constructor
A new instance of Locker.
- #lock(producer:, record:) ⇒ Object
- #locked?(producer:, record:) ⇒ Boolean
- #unlock(producer:, record:) ⇒ Object
Constructor Details
#initialize ⇒ Locker
Returns a new instance of Locker.
10 11 12 |
# File 'lib/concurrent_pipeline/pipelines/processors/locker.rb', line 10 def initialize @locks = {} end |
Instance Attribute Details
#locks ⇒ Object (readonly)
Returns the value of attribute locks.
9 10 11 |
# File 'lib/concurrent_pipeline/pipelines/processors/locker.rb', line 9 def locks @locks end |
Instance Method Details
#lock(producer:, record:) ⇒ Object
18 19 20 |
# File 'lib/concurrent_pipeline/pipelines/processors/locker.rb', line 18 def lock(producer:, record:) locks[[producer, record.class.name, record.id]] = true end |
#locked?(producer:, record:) ⇒ Boolean
14 15 16 |
# File 'lib/concurrent_pipeline/pipelines/processors/locker.rb', line 14 def locked?(producer:, record:) locks.key?([producer, record.class.name, record.id]) end |
#unlock(producer:, record:) ⇒ Object
22 23 24 |
# File 'lib/concurrent_pipeline/pipelines/processors/locker.rb', line 22 def unlock(producer:, record:) locks.delete([producer, record.class.name, record.id]) end |