lib/u3d/unity_runner.rb in u3d-1.2.3 vs lib/u3d/unity_runner.rb in u3d-1.3.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + ## --- BEGIN LICENSE BLOCK --- # Copyright (c) 2016-present WeWantToKnow AS # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -43,10 +45,11 @@ end if log_file tail_thread = start_tail_thread(log_file, output_callback) return unless tail_thread.status + tail_thread.run end begin args.unshift(installation.exe_path) @@ -76,22 +79,23 @@ FileUtils.touch(log_file) unless File.exist? log_file log_file end class << self - # rubocop:disable MethodName + # rubocop:disable Naming/MethodName def find_logFile_in_args(args) - # rubocop:enable MethodName + # rubocop:enable Naming/MethodName find_arg_in_args('-logFile', args) end def find_projectpath_in_args(args) find_arg_in_args('-projectPath', args) end def find_arg_in_args(arg_to_find, args) raise 'Only arguments of type array supported right now' unless args.is_a?(Array) + args.each_with_index do |arg, index| return args[index + 1] if arg == arg_to_find && index < args.count - 1 end nil end @@ -99,30 +103,28 @@ private def start_tail_thread(log_file, output_callback) tail_thread = Thread.new do - begin - pipe(log_file) { |line| output_callback.call(line) } - rescue StandardError => e - UI.error "Failure while trying to pipe #{log_file}: #{e.message}" - e.backtrace.each { |l| UI.error " #{l}" } - end + pipe(log_file) { |line| output_callback.call(line) } + rescue StandardError => e + UI.error "Failure while trying to pipe #{log_file}: #{e.message}" + e.backtrace.each { |l| UI.error " #{l}" } end # Wait for tail_thread setup to be complete sleep 0.5 while tail_thread.status == 'run' tail_thread end - def pipe(file) + def pipe(file, &block) File.open(file, 'r') do |f| f.extend File::Tail f.interval = 0.1 f.max_interval = 0.4 f.backward 0 Thread.stop - f.tail { |l| yield l } + f.tail(&block) end end end end