Module: Lore::Behaviours::Lockable
- Defined in:
- lib/lore/behaviours/lockable.rb
Instance Method Summary collapse
- #lock!(inst) ⇒ Object
-
#lock_by(attrib, &block) ⇒ Object
Defines which attribute to use for locking.
-
#locked?(inst) ⇒ Boolean
def.
-
#release!(inst) ⇒ Object
def.
Instance Method Details
#lock!(inst) ⇒ Object
24 25 26 27 |
# File 'lib/lore/behaviours/lockable.rb', line 24 def lock!(inst) inst[@lock_attr] = true commit end |
#lock_by(attrib, &block) ⇒ Object
Defines which attribute to use for locking. Default is ‘lock’. Usage:
If a block is given, a lock is only set when it evaluates to true:
lock_by(:lock) { |me|
me.user_id != $user.user_id
}
18 19 20 21 22 |
# File 'lib/lore/behaviours/lockable.rb', line 18 def lock_by(attrib, &block) @lock_proc = block @lock_attr = attrib @lock_attr_name = attrib.to_s.split('.')[-1].intern end |
#locked?(inst) ⇒ Boolean
def
34 35 36 |
# File 'lib/lore/behaviours/lockable.rb', line 34 def locked?(inst) (inst[@lock_attr] == true) || (inst[@lock_attr] == 't') end |
#release!(inst) ⇒ Object
def
29 30 31 32 |
# File 'lib/lore/behaviours/lockable.rb', line 29 def release!(inst) inst[@lock_attr] = false commit end |