Class: Lolcommits::CLI::ProcessRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/lolcommits/cli/process_runner.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ProcessRunner

Initializes a new process runner.

Parameters:



10
11
12
# File 'lib/lolcommits/cli/process_runner.rb', line 10

def initialize(config)
  @configuration = config
end

Instance Method Details

#fork_me?(please) { ... } ⇒ Boolean

Forks the lolcommits process if requested.

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

Parameters:

  • please (Boolean)

    whether or not to fork lolcommits process

Yields:

  • the main event loop for lolcommits

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
# 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