Sha256: 55c7741bf1c61e2026907b5474f967df3db2db4fc8d9bba616dc85f51e0d4dc2

Contents?: true

Size: 470 Bytes

Versions: 1

Compression:

Stored size: 470 Bytes

Contents

require 'fileutils'
module Backdrop
  class PidFile
    attr_reader :file
    def initialize(file)
      @file = file 
    end
  
    def pid
      File.file?(@file) and IO.read(@file) 
    end
  
    def remove
      if self.pid
        FileUtils.rm @file 
      end
    end
  
    def create
      File.open(@file, "w") { |f| f.write($$) }
    end
  
    def ensure_empty!(msg = nil)
      if self.pid
        puts msg if msg
        exit 1
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cicloid-backdrop-0.1.0 lib/backdrop/pid_file.rb