Class: Locksy::LockInterface

Inherits:
Object
  • Object
show all
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

BaseLock

Instance Attribute Summary collapse

Instance Method Summary collapse

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_expiryObject (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_extensionObject (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_nameObject (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

Parameters:

  • value

    the value to set the attribute logger to.



9
10
11
# File 'lib/locksy/lock_interface.rb', line 9

def logger=(value)
  @logger = value
end

#ownerObject (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