Class: LockedProcess
- Inherits:
-
Object
- Object
- LockedProcess
- Defined in:
- lib/locked_process.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
'0.0.1'
Instance Attribute Summary collapse
-
#pid_file ⇒ Object
readonly
Returns the value of attribute pid_file.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(pid_file) ⇒ LockedProcess
constructor
A new instance of LockedProcess.
- #pid_file_exists? ⇒ Boolean
Constructor Details
#initialize(pid_file) ⇒ LockedProcess
Returns a new instance of LockedProcess.
10 11 12 13 14 15 16 17 |
# File 'lib/locked_process.rb', line 10 def initialize(pid_file) unless block_given? raise ArgumentError.new('Block must be given') end @process = lambda { yield } @pid_file = pid_file end |
Instance Attribute Details
#pid_file ⇒ Object (readonly)
Returns the value of attribute pid_file.
8 9 10 |
# File 'lib/locked_process.rb', line 8 def pid_file @pid_file end |
Instance Method Details
#execute ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/locked_process.rb', line 23 def execute create_pid_file Thread.new do @process.call remove_pid_file end end |
#pid_file_exists? ⇒ Boolean
19 20 21 |
# File 'lib/locked_process.rb', line 19 def pid_file_exists? File.exists?(pid_file) end |