Class: Locksy::BaseLock
- Inherits:
-
LockInterface
- Object
- LockInterface
- Locksy::BaseLock
- Defined in:
- lib/locksy/base_lock.rb
Instance Attribute Summary collapse
-
#_clock ⇒ Object
writeonly
allow injection of a clock to assist testing do not call or set this outside of tests.
-
#default_expiry ⇒ Object
readonly
Returns the value of attribute default_expiry.
-
#default_extension ⇒ Object
readonly
Returns the value of attribute default_extension.
-
#lock_name ⇒ Object
readonly
Returns the value of attribute lock_name.
-
#logger ⇒ Object
writeonly
Sets the attribute logger.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(lock_name: generate_default_lock_name, owner: generate_default_owner, default_expiry: 10, default_extension: 10, logger: nil, **_args) ⇒ BaseLock
constructor
A new instance of BaseLock.
-
#obtain_lock(expire_after: default_expiry, **_args) ⇒ Object
disabling here because we have a no-op implementation…
- #refresh_lock(expire_after: default_extension, **_args) ⇒ Object
- #release_lock(**_args) ⇒ Object
-
#with_lock(expire_after: default_expiry, **args) ⇒ Object
rubocop:enable Style/EmptyMethod.
Constructor Details
#initialize(lock_name: generate_default_lock_name, owner: generate_default_owner, default_expiry: 10, default_extension: 10, logger: nil, **_args) ⇒ BaseLock
Returns a new instance of BaseLock.
19 20 21 22 23 24 25 26 |
# File 'lib/locksy/base_lock.rb', line 19 def initialize(lock_name: generate_default_lock_name, owner: generate_default_owner, default_expiry: 10, default_extension: 10, logger: nil, **_args) @owner = owner @default_expiry = default_expiry @default_extension = default_extension @lock_name = lock_name @logger = logger end |
Instance Attribute Details
#_clock=(value) ⇒ Object (writeonly)
allow injection of a clock to assist testing do not call or set this outside of tests
14 15 16 |
# File 'lib/locksy/base_lock.rb', line 14 def _clock=(value) @_clock = value end |
#default_expiry ⇒ Object (readonly)
Returns the value of attribute default_expiry.
9 10 11 |
# File 'lib/locksy/base_lock.rb', line 9 def default_expiry @default_expiry end |
#default_extension ⇒ Object (readonly)
Returns the value of attribute default_extension.
9 10 11 |
# File 'lib/locksy/base_lock.rb', line 9 def default_extension @default_extension end |
#lock_name ⇒ Object (readonly)
Returns the value of attribute lock_name.
9 10 11 |
# File 'lib/locksy/base_lock.rb', line 9 def lock_name @lock_name end |
#logger=(value) ⇒ Object
Sets the attribute logger
10 11 12 |
# File 'lib/locksy/base_lock.rb', line 10 def logger=(value) @logger = value end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
9 10 11 |
# File 'lib/locksy/base_lock.rb', line 9 def owner @owner end |
Class Method Details
.shutting_down? ⇒ Boolean
46 47 48 |
# File 'lib/locksy/base_lock.rb', line 46 def self.shutting_down? @_shutting_down end |
Instance Method Details
#obtain_lock(expire_after: default_expiry, **_args) ⇒ Object
disabling here because we have a no-op implementation… we’re expecting this class to be extended rubocop:disable Style/EmptyMethod
31 |
# File 'lib/locksy/base_lock.rb', line 31 def obtain_lock(expire_after: default_expiry, **_args); end |
#refresh_lock(expire_after: default_extension, **_args) ⇒ Object
33 |
# File 'lib/locksy/base_lock.rb', line 33 def refresh_lock(expire_after: default_extension, **_args); end |
#release_lock(**_args) ⇒ Object
35 |
# File 'lib/locksy/base_lock.rb', line 35 def release_lock(**_args); end |
#with_lock(expire_after: default_expiry, **args) ⇒ Object
rubocop:enable Style/EmptyMethod
38 39 40 41 42 43 44 |
# File 'lib/locksy/base_lock.rb', line 38 def with_lock(expire_after: default_expiry, **args) if (lock_obtained = obtain_lock(expire_after: expire_after, **args)) yield end ensure release_lock if lock_obtained end |