Class: Phantom::Phutex
- Inherits:
-
Object
- Object
- Phantom::Phutex
- Defined in:
- lib/phantom/phutex.rb
Instance Method Summary collapse
-
#initialize(lock_path) ⇒ Phutex
constructor
A new instance of Phutex.
- #sync(&block) ⇒ Object
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
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 |