class PhTools::Runner
Main class processing input stream
Public Class Methods
new(usage, file_type = [])
click to toggle source
# File lib/phtools/runner.rb, line 17 def initialize(usage, file_type = []) case Utils.os when :windows # workaround for win32 ARGV.map! { |a| a.encode('utf-8', 'filesystem') } @os = Utils::OSWin.new else @os = Utils::OSUnix.new end @tool_name = File.basename($PROGRAM_NAME) @options_cli = Docopt.docopt(usage, version: "v#{PhTools::VERSION}") @file_type = file_type PhTools.debug = true if @options_cli['--debug'] validate_options rescue Docopt::Exit => e STDERR.puts e.message exit 1 rescue StandardError => e PhTools.puts_error "FATAL: #{e.message}", e exit 1 ensure if PhTools.debug STDERR.puts 'Runner Instance Variables: ' STDERR.puts context end end
Public Instance Methods
run!()
click to toggle source
# File lib/phtools/runner.rb, line 45 def run! return if STDIN.tty? ARGV.clear process_before ARGF.each_line do |line| filename = line.chomp begin PhFile.validate_file!(filename, @file_type) phfile = PhFile.new(filename) @os.output process_file(phfile) rescue PhTools::Error => e PhTools.puts_error "ERROR: '#{filename}' - #{e.message}", e end end process_after rescue SignalException PhTools.puts_error 'EXIT on user interrupt Ctrl-C' exit 1 rescue StandardError => e PhTools.puts_error "FATAL: #{e.message}", e exit 1 end
Private Instance Methods
context()
click to toggle source
# File lib/phtools/runner.rb, line 82 def context instance_variables.map do |item| { item => instance_variable_get(item) } end end
process_after()
click to toggle source
# File lib/phtools/runner.rb, line 80 def process_after; end
process_before()
click to toggle source
# File lib/phtools/runner.rb, line 74 def process_before; end
process_file(file)
click to toggle source
# File lib/phtools/runner.rb, line 76 def process_file(file) file end
validate_options()
click to toggle source
# File lib/phtools/runner.rb, line 72 def validate_options; end