lib/multi_process/process.rb in multi_process-0.4.0 vs lib/multi_process/process.rb in multi_process-0.5.0
- old
+ new
@@ -1,15 +1,15 @@
require 'active_support/core_ext/module/delegation'
module MultiProcess
-
+ #
# Describes a single process that can be configured and run.
#
# {Process} basically is just a thin wrapper around {ChildProcess}.
#
class Process
- #@!group Process
+ # @!group Process
# Process title used in e.g. logger
attr_reader :title
# Command as full string.
@@ -21,11 +21,11 @@
def initialize(*args)
args.flatten!
opts = (Hash === args.last ? args.pop : {})
@title = opts[:title].to_s || args.first.to_s.strip.split(/\s+/, 2)[0]
- @command = args.map{ |arg| (arg =~ /\A[\s"']+\z/ ? arg.inspect : arg).gsub '"', '\"' }.join(' ')
+ @command = args.map { |arg| (arg =~ /\A[\s"']+\z/ ? arg.inspect : arg).gsub '"', '\"' }.join(' ')
@childprocess = create_childprocess *args
@env = opts[:env] if Hash === opts[:env]
@env_clean = opts[:clean_env].nil? ? true : !!opts[:clean_env]
@@ -61,11 +61,11 @@
#
def start
return false if started?
at_exit { stop }
- receiver.message(self, :sys, self.command) if receiver
+ receiver.message(self, :sys, command) if receiver
start_childprocess
@started = true
end
# Stop process.
@@ -114,24 +114,24 @@
def run(opts = {})
start
wait opts
end
- #@!group Working Directory
+ # @!group Working Directory
# Working directory for child process.
attr_reader :dir
# Set process working directory. Only affect process if set before
# starting.
#
def dir=(dir)
@dir = ::File.expand_path(dir.to_s)
- self.env['PWD'] = @dir
+ env['PWD'] = @dir
end
- #@!group Environment
+ # @!group Environment
# Check if environment will be cleaned up for process.
#
# Currently that includes wrapping the process start in
# `Bundler.with_clean_env` to remove bundler environment
@@ -142,21 +142,21 @@
end
# Return current environment.
#
def env
- @env ||= Hash.new
+ @env ||= {}
end
# Set environment.
#
def env=(env)
- raise ArgumentError.new 'Environment must be a Hash.' unless hash === env
+ fail ArgumentError.new 'Environment must be a Hash.' unless hash === env
@env = env
end
- #@!group Receiver
+ # @!group Receiver
# Current receiver. Defaults to `MultiProcess::Logger.global`.
#
attr_reader :receiver
@@ -184,10 +184,10 @@
# Start child process.
#
# Can be used to hook in subclasses and modules.
#
def start_childprocess
- env.each{|k, v| childprocess.environment[k.to_s] = v.to_s }
+ env.each { |k, v| childprocess.environment[k.to_s] = v.to_s }
childprocess.cwd = dir
if clean_env?
Bundler.with_clean_env { childprocess.start }
else