A simple Lock File class written in Ruby.
en.wikipedia.org/wiki/Lock_file#Lock_files
From Gemcutter:
gem install simple_lockfile
The project page is located at gemcutter.org/gems/simple_lockfile.
require 'lockfile' l = LockFile.new("/Users/joshnesbitt/Desktop", "test.lock") # => "/Users/joshnesbitt/Desktop/test.lock" l.locked? # => false l.lock! # => Integer value l.locked? # => true l.process_id # => PID l.unlock! # => Integer value l.locked? # => false
I commonly use it for checking whether an expensive task is being executed:
refresh_search_index unless @lockfile.locked?
And in the method something like this:
def refresh_search_index @lockfile.lock! # ... some heavy operation ... @lockfile.unlock! end
Specs are run using Watchr (github.com/mynyml/watchr) to observe the /lib and /spec directories for any changes. Once installed simply do:
watchr spec/watch.rb
You don’t have to use Watchr to run the specs, I just prefer to use it over autotest as its lightweight, quick and works. You could just run the specs normally.
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
-
Greg Fitzgerald (github.com/gregf) - Gemification of LockFile.
Copyright © 2010 Josh Nesbitt <[email protected]>. See LICENSE for details.