Class: Restruct::Locker

Inherits:
Structure show all
Defined in:
lib/restruct/locker.rb

Constant Summary collapse

REGISTER_LUA =
File.read "#{File.dirname(__FILE__)}/../../lua/register.lua"
UNREGISTER_LUA =
File.read "#{File.dirname(__FILE__)}/../../lua/unregister.lua"

Instance Attribute Summary

Attributes inherited from Structure

#connection, #id

Instance Method Summary collapse

Methods inherited from Structure

#==, #destroy, #dump, #exists?, #initialize, #restore

Constructor Details

This class inherits a constructor from Restruct::Structure

Instance Method Details

#keyObject Also known as: locked_by



19
20
21
# File 'lib/restruct/locker.rb', line 19

def key
  connection.call('HGET', id, 'key')
end

#lock(key, &block) ⇒ Object



7
8
9
# File 'lib/restruct/locker.rb', line 7

def lock(key, &block)
  _lock key, false, &block
end

#lock!(key, &block) ⇒ Object



11
12
13
# File 'lib/restruct/locker.rb', line 11

def lock!(key, &block)
  _lock key, true, &block
end

#to_hObject Also known as: to_primitive



24
25
26
# File 'lib/restruct/locker.rb', line 24

def to_h
  ::Hash[connection.call('HGETALL', id).each_slice(2).to_a]
end