Class: Locksy::LockInterface
- Inherits:
-
Object
- Object
- Locksy::LockInterface
- Defined in:
- lib/locksy/lock_interface.rb
Overview
AbstractLock allows us to declare the interface for locks. Any locks created should follow this interface
disabling this cop because we are declaring this as an interface and deliberately not using here rubocop:disable Lint/UnusedMethodArgument
Direct Known Subclasses
Instance Attribute Summary collapse
-
#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.
Instance Method Summary collapse
-
#initialize(lock_name: generate_default_lock_name, owner: generate_default_owner, default_expiry: nil, default_extension: nil, logger: nil, **_args) ⇒ LockInterface
constructor
A new instance of LockInterface.
-
#obtain_lock(expire_after: default_expiry, **_args) ⇒ Object
should return a boolean denoting lock obtained (true) or not (false).
-
#refresh_lock(expire_after: default_extension, **_args) ⇒ Object
should raise a LockNotOwnedError if the lock is not owned by the requested owner.
-
#release_lock(**_args) ⇒ Object
should raise a LockNotOwnedError if the lock is not owned by the requested owner.
-
#with_lock(expire_after: default_expiry, **_args) ⇒ Object
should raise a LockNotOwnedError if the lock is not owned by the requested owner.
Constructor Details
#initialize(lock_name: generate_default_lock_name, owner: generate_default_owner, default_expiry: nil, default_extension: nil, logger: nil, **_args) ⇒ LockInterface
Returns a new instance of LockInterface.
11 12 13 14 |
# File 'lib/locksy/lock_interface.rb', line 11 def initialize(lock_name: generate_default_lock_name, owner: generate_default_owner, default_expiry: nil, default_extension: nil, logger: nil, **_args) raise NotImplementedError.new 'This is an abstract class - instantiation is not supported' end |
Instance Attribute Details
#default_expiry ⇒ Object (readonly)
Returns the value of attribute default_expiry.
8 9 10 |
# File 'lib/locksy/lock_interface.rb', line 8 def default_expiry @default_expiry end |
#default_extension ⇒ Object (readonly)
Returns the value of attribute default_extension.
8 9 10 |
# File 'lib/locksy/lock_interface.rb', line 8 def default_extension @default_extension end |
#lock_name ⇒ Object (readonly)
Returns the value of attribute lock_name.
8 9 10 |
# File 'lib/locksy/lock_interface.rb', line 8 def lock_name @lock_name end |
#logger=(value) ⇒ Object
Sets the attribute logger
9 10 11 |
# File 'lib/locksy/lock_interface.rb', line 9 def logger=(value) @logger = value end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
8 9 10 |
# File 'lib/locksy/lock_interface.rb', line 8 def owner @owner end |
Instance Method Details
#obtain_lock(expire_after: default_expiry, **_args) ⇒ Object
should return a boolean denoting lock obtained (true) or not (false)
17 18 19 |
# File 'lib/locksy/lock_interface.rb', line 17 def obtain_lock(expire_after: default_expiry, **_args) raise NotImplementedError.new 'Obtaining a lock is not supported' end |
#refresh_lock(expire_after: default_extension, **_args) ⇒ Object
should raise a LockNotOwnedError if the lock is not owned by the requested owner
22 23 24 |
# File 'lib/locksy/lock_interface.rb', line 22 def refresh_lock(expire_after: default_extension, **_args) raise NotImplementedError.new 'Refreshing a lock is not supported' end |
#release_lock(**_args) ⇒ Object
should raise a LockNotOwnedError if the lock is not owned by the requested owner
27 28 29 |
# File 'lib/locksy/lock_interface.rb', line 27 def release_lock(**_args) raise NotImplementedError.new 'Releasing a lock is not supported' end |
#with_lock(expire_after: default_expiry, **_args) ⇒ Object
should raise a LockNotOwnedError if the lock is not owned by the requested owner
32 33 34 |
# File 'lib/locksy/lock_interface.rb', line 32 def with_lock(expire_after: default_expiry, **_args) raise NotImplementedError.new 'Working with a lock is not supported' end |