Class: Phantom::Phutex

Inherits:
Object
  • Object
show all
Defined in:
lib/phantom/phutex.rb

Instance Method Summary collapse

Constructor Details

#initialize(lock_path) ⇒ Phutex

Returns a new instance of Phutex.



3
4
5
# File 'lib/phantom/phutex.rb', line 3

def initialize(lock_path)
  @path = lock_path
end

Instance Method Details

#sync(&block) ⇒ Object

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
# File 'lib/phantom/phutex.rb', line 7

def sync(&block)
  raise ArgumentError.new('Block must be given.') if not block_given?
  File.open(@path, 'w') do |f|
    f.flock(File::LOCK_EX)
    block.call
  end
end