Module: Narou::Mixin::Locker
- Included in:
- Narou
- Defined in:
- lib/mixin/locker.rb
Instance Method Summary collapse
Instance Method Details
#lock(target) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mixin/locker.rb', line 15 def lock(target) id = Downloader.get_id_by_target(target) unless id yield if block_given? return end locked_list = Inventory.load("lock") locked_list[id] = Time.now locked_list.save return unless block_given? begin yield ensure unlock(target) end end |
#locked?(target) ⇒ Boolean
10 11 12 13 |
# File 'lib/mixin/locker.rb', line 10 def locked?(target) id = Downloader.get_id_by_target(target) or return false Inventory.load("lock").include?(id) end |
#unlock(target) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/mixin/locker.rb', line 32 def unlock(target) id = Downloader.get_id_by_target(target) or return locked_list = Inventory.load("lock") return unless locked_list.delete(id) locked_list.save end |