Module: Lore::Behaviours::Lockable
- Defined in:
- lib/lore/behaviours/lockable.rb
Instance Method Summary collapse
- #lock!(inst) ⇒ Object
-
#lock_by(attrib) ⇒ Object
Defines which attribute to use for locking.
-
#locked?(inst) ⇒ Boolean
def.
-
#release!(inst) ⇒ Object
def.
Instance Method Details
#lock!(inst) ⇒ Object
28 29 30 31 |
# File 'lib/lore/behaviours/lockable.rb', line 28 def lock!(inst) inst.attr[@lock_attr] = true commit end |
#lock_by(attrib) ⇒ Object
Defines which attribute to use for locking. Usage:
class My_Model < Lore::Model
extend Lockable
include Lockable_Entity
# ...
lock_by(:lock_field)
end
my_model_entity.lock!
# same as
My_Model.lock!(my_model_entity)
23 24 25 26 |
# File 'lib/lore/behaviours/lockable.rb', line 23 def lock_by(attrib) @lock_attr = attrib @lock_attr_name = attrib.to_s.split('.')[-1].intern end |
#locked?(inst) ⇒ Boolean
def
36 37 38 |
# File 'lib/lore/behaviours/lockable.rb', line 36 def locked?(inst) (inst.attr[@lock_attr] == true) || (inst.attr[@lock_attr] == 't') end |
#release!(inst) ⇒ Object
def
32 33 34 35 |
# File 'lib/lore/behaviours/lockable.rb', line 32 def release!(inst) inst.attr[@lock_attr] = false commit end |