Class: PidFile

Inherits:
Object
  • Object
show all
Defined in:
lib/arldap/pid_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fileObject (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

#createObject



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

#pidObject



8
9
10
# File 'lib/arldap/pid_file.rb', line 8

def pid
  File.file?(@file) and IO.read(@file) 
end

#removeObject



12
13
14
15
16
# File 'lib/arldap/pid_file.rb', line 12

def remove
  if self.pid
    FileUtils.rm @file 
  end
end