module Fontist::Utils::Locking

Public Instance Methods

lock(lock_path) { || ... } click to toggle source
# File lib/fontist/utils/locking.rb, line 4
def lock(lock_path)
  File.dirname(lock_path).tap do |dir|
    FileUtils.mkdir_p(dir) unless File.exist?(dir)
  end

  f = File.open(lock_path, File::CREAT)
  f.flock(File::LOCK_EX)
  yield
ensure
  f.flock(File::LOCK_UN)
  f.close
end