Class: PidFile
- Inherits:
-
Object
- Object
- PidFile
- Defined in:
- lib/arldap/pid_file.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #create ⇒ Object
- #ensure_empty!(msg = nil) ⇒ Object
-
#initialize(file) ⇒ PidFile
constructor
A new instance of PidFile.
- #pid ⇒ Object
- #remove ⇒ Object
Constructor Details
#initialize(file) ⇒ PidFile
Returns a new instance of PidFile.
4 5 6 |
# File 'lib/arldap/pid_file.rb', line 4 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
3 4 5 |
# File 'lib/arldap/pid_file.rb', line 3 def file @file end |
Instance Method Details
#create ⇒ Object
18 19 20 |
# File 'lib/arldap/pid_file.rb', line 18 def create File.open(@file, "w") { |f| f.write($$) } end |
#ensure_empty!(msg = nil) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/arldap/pid_file.rb', line 22 def ensure_empty!(msg = nil) if self.pid puts msg if msg exit 1 end end |
#pid ⇒ Object
8 9 10 |
# File 'lib/arldap/pid_file.rb', line 8 def pid File.file?(@file) and IO.read(@file) end |
#remove ⇒ Object
12 13 14 15 16 |
# File 'lib/arldap/pid_file.rb', line 12 def remove if self.pid FileUtils.rm @file end end |