class GemFootprintAnalyzer::CLI

A command line interface class for the gem. Provides options parsing and help messages for the user.

Attributes

options[R]
opts[R]

Public Class Methods

new() click to toggle source

Sets default options, to be overwritten by option parser down the road

# File lib/gem_footprint_analyzer/cli.rb, line 8
def initialize
  @options = {}
  @options[:runs] = 10
  @options[:debug] = false
  @options[:formatter] = 'tree'

  @opts = Opts.new(@options)
end

Public Instance Methods

run(args = ARGV) click to toggle source

@param args [Array<String>] runs the analyzer with parsed args taken as options @return [void]

# File lib/gem_footprint_analyzer/cli.rb, line 19
def run(args = ARGV)
  opts.parse!(args)

  if !analyze_gemfile? && args.empty?
    puts opts.parser
    exit 1
  end

  print_requires(options, args)
end

Private Instance Methods

analyze_gemfile?() click to toggle source
# File lib/gem_footprint_analyzer/cli.rb, line 72
def analyze_gemfile?
  options[:analyze_gemfile]
end
capture_requires(options, args) click to toggle source
# File lib/gem_footprint_analyzer/cli.rb, line 42
def capture_requires(options, args)
  GemFootprintAnalyzer::AverageRunner.new(options[:runs]) do
    fifos = init_fifos

    GemFootprintAnalyzer::Analyzer.new(fifos, options).test_library(*args).tap do
      clean_up_fifos(fifos)
    end
  end.run
end
clean_up_fifos(fifos) click to toggle source
# File lib/gem_footprint_analyzer/cli.rb, line 63
def clean_up_fifos(fifos)
  fifos.each { |_, name| File.unlink(name) if File.exist?(name) }
  Dir.unlink(File.dirname(fifos[:parent]))
end
formatter_instance(options) click to toggle source
# File lib/gem_footprint_analyzer/cli.rb, line 68
def formatter_instance(options)
  GemFootprintAnalyzer::Formatters.const_get(options[:formatter].capitalize)
end
init_fifos() click to toggle source
# File lib/gem_footprint_analyzer/cli.rb, line 52
def init_fifos
  dir = Dir.mktmpdir
  parent_name = File.join(dir, 'parent.fifo')
  child_name = File.join(dir, 'child.fifo')

  File.mkfifo(parent_name)
  File.mkfifo(child_name)

  {parent: parent_name, child: child_name}
end
print_requires(options, args) click to toggle source