class Lolcommits::CLI::ProcessRunner

Helper class for forking lolcommits process to the background (or not).

Public Class Methods

new(config) click to toggle source

Initializes a new process runner.

@param config [Lolcommits::Configuration]

# File lib/lolcommits/cli/process_runner.rb, line 10
def initialize(config)
  @configuration = config
end

Public Instance Methods

fork_me?(please) { |block| ... } click to toggle source

Forks the lolcommits process if requested.

Writes the PID of the lolcommits process to the filesystem when backgrounded, for monitoring purposes.

@param please [Boolean] whether or not to fork lolcommits process @yield the main event loop for lolcommits

# File lib/lolcommits/cli/process_runner.rb, line 21
def fork_me?(please, &block)
  if please
    $stdout.sync = true
    write_pid fork {
      yield block
      delete_pid
    }
  else
    yield block
  end
end

Private Instance Methods

delete_pid() click to toggle source
# File lib/lolcommits/cli/process_runner.rb, line 39
def delete_pid
  File.delete(pid_file) if File.exist?(pid_file)
end
pid_file() click to toggle source
# File lib/lolcommits/cli/process_runner.rb, line 43
def pid_file
  File.join(@configuration.loldir, 'lolcommits.pid')
end
write_pid(pid) click to toggle source
# File lib/lolcommits/cli/process_runner.rb, line 35
def write_pid(pid)
  File.open(pid_file, 'w') { |f| f.write(pid) }
end