Sha256: 2f279bbea06a1867ba998b5e36e325e90ef3cc56f2dfc240f9c537e5bd5d1a0d
Contents?: true
Size: 1.14 KB
Versions: 12
Compression:
Stored size: 1.14 KB
Contents
# frozen_string_literal: true module Lolcommits module CLI # Helper class for forking lolcommits process to the background (or not). class ProcessRunner # Initializes a new process runner. # # @param config [Lolcommits::Configuration] def initialize(config) @configuration = config end # 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 def fork_me?(please, &block) if please $stdout.sync = true write_pid fork { yield block delete_pid } else yield block end end private def write_pid(pid) File.open(pid_file, 'w') { |f| f.write(pid) } end def delete_pid File.delete(pid_file) if File.exist?(pid_file) end def pid_file File.join(@configuration.loldir, 'lolcommits.pid') end end end end
Version data entries
12 entries across 12 versions & 1 rubygems