class GemFootprintAnalyzer::ChildProcess
A class for starting the child process that does actual requires.
Constants
- LEGACY_RUBY_CMD
- RUBY_CMD
Attributes
child_thread[R]
fifos[R]
options[R]
require_string[R]
Public Class Methods
new(library, require_string, fifos, options = {})
click to toggle source
Sets necessary ivars
# File lib/gem_footprint_analyzer/child_process.rb, line 11 def initialize(library, require_string, fifos, options = {}) @library = library @require_string = require_string || library @fifos = fifos @pid = nil @options = options end
Public Instance Methods
pid()
click to toggle source
Blocking method @return [Integer|nil] Process id or nil, if the child-watching-thread is not started
# File lib/gem_footprint_analyzer/child_process.rb, line 35 def pid return unless child_thread sleep 0.01 while @pid.nil? @pid end
start_child()
click to toggle source
Starts a child process in a child-watching-thread Reads it's PID from the new process' STDOUT and sets it as an instance variable
# File lib/gem_footprint_analyzer/child_process.rb, line 21 def start_child @child_thread ||= Thread.new do # rubocop:disable Naming/MemoizedInstanceVariableName Open3.popen3(child_env_vars, *ruby_command, context_file) do |_, stdout, stderr| @pid = stdout.gets.strip.to_i while (line = stderr.gets) print "!! #{line}" end end end end
Private Instance Methods
child_env_vars()
click to toggle source
# File lib/gem_footprint_analyzer/child_process.rb, line 54 def child_env_vars { 'require_string' => require_string, 'require_rubygems' => options.key?(:rubygems) && 'true' || nil, 'analyze_gemfile' => options.key?(:analyze_gemfile) && 'true' || nil, 'start_child_context' => 'true', 'child_fifo' => fifos[:child], 'parent_fifo' => fifos[:parent], 'RUBYOPT' => '', # Stop bundler from requiring bundler/setup 'RUBYLIB' => $LOAD_PATH.join(':') # Include bundler-provided paths and paths passed by user } end
context_file()
click to toggle source
# File lib/gem_footprint_analyzer/child_process.rb, line 67 def context_file File.join(__dir__, 'child_context.rb') end
ruby_command()
click to toggle source
# File lib/gem_footprint_analyzer/child_process.rb, line 46 def ruby_command if RbConfig::CONFIG['MAJOR'].to_i >= 2 && RbConfig::CONFIG['MINOR'].to_i >= 3 RUBY_CMD else LEGACY_RUBY_CMD end end