Class: EventHub::Pidfile

Inherits:
Object
  • Object
show all
Defined in:
lib/eventhub/pidfile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Pidfile

Returns a new instance of Pidfile.



3
4
5
# File 'lib/eventhub/pidfile.rb', line 3

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



2
3
4
# File 'lib/eventhub/pidfile.rb', line 2

def file
  @file
end

Instance Method Details

#deleteObject

Try to delete file, ignore all errors



14
15
16
17
18
19
20
# File 'lib/eventhub/pidfile.rb', line 14

def delete
  begin
    File.delete(file)
  rescue
    # ignore
  end
end

#write(pid) ⇒ Object

write the pid to the file specified in the initializer



8
9
10
11
# File 'lib/eventhub/pidfile.rb', line 8

def write(pid)
  FileUtils.makedirs(File.dirname(file))
  IO.write(file, pid.to_s)
end