Module: LockIt::Mixin
- Included in:
- Dir
- Defined in:
- lib/lockit.rb
Instance Method Summary collapse
-
#lock(args = {}) ⇒ Object
Lock the directory.
- #lock_info ⇒ Object
- #locked? ⇒ Boolean
- #revise_lock(args) ⇒ Object
-
#try_lock(args = {}) ⇒ Object
If the directory is locked already, return false Otherwise, lock the directory.
- #unlock ⇒ Object
- #unlock! ⇒ Object
Instance Method Details
#lock(args = {}) ⇒ Object
Lock the directory
8 9 10 11 12 |
# File 'lib/lockit.rb', line 8 def lock args = {} return false if locked? write_lock args self end |
#lock_info ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lockit.rb', line 42 def lock_info f = closest_lock_file header, obtained, id, release = open(f).read.split("\n").first.split(" ") info = {} info[:file] = f info[:obtained] = obtained info[:id] = id info[:release] = release if release info end |
#locked? ⇒ Boolean
29 30 31 32 |
# File 'lib/lockit.rb', line 29 def locked? return true if closest_lock_file false end |
#revise_lock(args) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/lockit.rb', line 15 def revise_lock args return false unless locked? # xxx is it my lock to revise? write_lock args self end |
#try_lock(args = {}) ⇒ Object
If the directory is locked already, return false Otherwise, lock the directory
24 25 26 27 |
# File 'lib/lockit.rb', line 24 def try_lock args = {} return false if locked? lock args end |
#unlock ⇒ Object
34 35 36 |
# File 'lib/lockit.rb', line 34 def unlock unlock! end |
#unlock! ⇒ Object
38 39 40 |
# File 'lib/lockit.rb', line 38 def unlock! FileUtils.rm lock_file end |