From 1897392a459651aa26ec0566a2e4b60a68aee38b Mon Sep 17 00:00:00 2001 From: Colin Kelley Date: Mon, 29 Mar 2021 23:08:17 -0700 Subject: [PATCH 1/7] add ruby 2.2, 2.3, and 2.4 to CI matrix --- .github/workflows/development.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index e45b6458..c61654d3 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -14,6 +14,9 @@ jobs: - macos ruby: + - 2.2 + - 2.3 + - 2.4 - 2.5 - 2.6 - 2.7 From b9df36ad64d47337041019d7111c531c7b6126f7 Mon Sep 17 00:00:00 2001 From: Colin Kelley Date: Mon, 29 Mar 2021 23:20:08 -0700 Subject: [PATCH 2/7] skip rubocop when ruby version < 2.4 --- Gemfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 2ccc8c85..8b1e9805 100644 --- a/Gemfile +++ b/Gemfile @@ -26,14 +26,16 @@ group :test do gem 'rspec', '~> 3.3' end +RUBY_VERSION_FLOAT = RUBY_VERSION[/\d+\.\d+/].to_f + group :development do gem 'bundler' gem 'gems', require: false gem 'guard-rspec', require: false - gem 'guard-rubocop' + gem 'guard-rubocop' unless RUBY_VERSION_FLOAT < 2.4 gem 'netrc', require: false gem 'octokit', require: false gem 'pry-rescue' - gem 'rubocop', '0.91.0' + gem 'rubocop', '0.91.0' unless RUBY_VERSION_FLOAT < 2.4 gem 'yard', require: false end From c158d8acf2f953d08fe3be9213c9159a7bac011c Mon Sep 17 00:00:00 2001 From: Colin Kelley Date: Mon, 29 Mar 2021 23:25:58 -0700 Subject: [PATCH 3/7] avoid &. since it is not supported in ruby 2.2 --- lib/listen/adapter/base.rb | 2 +- lib/listen/adapter/darwin.rb | 2 +- lib/listen/adapter/linux.rb | 2 +- lib/listen/event/config.rb | 2 +- lib/listen/event/loop.rb | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/listen/adapter/base.rb b/lib/listen/adapter/base.rb index 3e1b19d0..630d1ddb 100644 --- a/lib/listen/adapter/base.rb +++ b/lib/listen/adapter/base.rb @@ -88,7 +88,7 @@ def stop private def _stop - @run_thread&.kill + @run_thread && @run_thread.kill @run_thread = nil end diff --git a/lib/listen/adapter/darwin.rb b/lib/listen/adapter/darwin.rb index 6106a145..a2229508 100644 --- a/lib/listen/adapter/darwin.rb +++ b/lib/listen/adapter/darwin.rb @@ -69,7 +69,7 @@ def _process_event(dir, path) end def _stop - @worker_thread&.kill + @worker_thread && @worker_thread.kill super end end diff --git a/lib/listen/adapter/linux.rb b/lib/listen/adapter/linux.rb index af732491..eefbece2 100644 --- a/lib/listen/adapter/linux.rb +++ b/lib/listen/adapter/linux.rb @@ -102,7 +102,7 @@ def _dir_event?(event) end def _stop - @worker&.close + @worker && @worker.close super end diff --git a/lib/listen/event/config.rb b/lib/listen/event/config.rb index c83ee37b..6d44698a 100644 --- a/lib/listen/event/config.rb +++ b/lib/listen/event/config.rb @@ -25,7 +25,7 @@ def sleep(seconds) end def call(*args) - @block&.call(*args) + @block && @block.call(*args) end def callable? diff --git a/lib/listen/event/loop.rb b/lib/listen/event/loop.rb index dd071f01..23115882 100644 --- a/lib/listen/event/loop.rb +++ b/lib/listen/event/loop.rb @@ -29,7 +29,7 @@ def initialize(config) end def wakeup_on_event - if started? && @wait_thread&.alive? + if started? && @wait_thread && @wait_thread.alive? _wakeup(:event) end end @@ -67,7 +67,7 @@ def pause def stop transition! :stopped - @wait_thread&.join + @wait_thread && @wait_thread.join @wait_thread = nil end From 3a8eea2d9bcf98a2687f6d1e75f15c08b4a5003d Mon Sep 17 00:00:00 2001 From: Colin Kelley Date: Mon, 29 Mar 2021 23:37:37 -0700 Subject: [PATCH 4/7] avoid <<~ since it is not supported in ruby 2.2 --- spec/lib/listen/thread_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/lib/listen/thread_spec.rb b/spec/lib/listen/thread_spec.rb index bd10f423..14f36d56 100644 --- a/spec/lib/listen/thread_spec.rb +++ b/spec/lib/listen/thread_spec.rb @@ -43,7 +43,7 @@ end it "rescues and logs exceptions" do - pattern = <<~EOS.strip + pattern = <<-EOS.gsub(/^ +/, '').strip Exception rescued in listen-worker_thread: ArgumentError: boom! .*\\/listen\\/thread_spec\\.rb @@ -53,7 +53,7 @@ end it "rescues and logs backtrace + exception backtrace" do - pattern = <<~EOS.strip + pattern = <<-EOS.gsub(/^ +/, '').strip Exception rescued in listen-worker_thread: ArgumentError: boom! .*\\/listen\\/thread\\.rb.*--- Thread.new ---.*\\/listen\\/thread_spec\\.rb @@ -93,7 +93,7 @@ class TestExceptionDerivedFromException < Exception; end # rubocop:disable Lint/ let(:block) { raise_nested_exception_block } it "details exception causes" do - pattern = <<~EOS + pattern = <<-EOS.gsub(/^ +/, '') RuntimeError: nested outer --- Caused by: --- RuntimeError: nested inner @@ -108,7 +108,7 @@ class TestExceptionDerivedFromException < Exception; end # rubocop:disable Lint/ describe '.rescue_and_log' do it 'rescues and logs nested exceptions' do - pattern = <<~EOS + pattern = <<-EOS.gsub(/^ +/, '') Exception rescued in method: RuntimeError: nested outer --- Caused by: --- From 7fa10c8a9ab9a676e943133b6af787151180a178 Mon Sep 17 00:00:00 2001 From: Colin Kelley Date: Mon, 29 Mar 2021 23:44:49 -0700 Subject: [PATCH 5/7] avoid Hash#transform_values since it is not supported in ruby 2.2 --- lib/listen/record.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/listen/record.rb b/lib/listen/record.rb index 4f8fedf0..a83bc4d8 100644 --- a/lib/listen/record.rb +++ b/lib/listen/record.rb @@ -45,16 +45,16 @@ def file_data(rel_path) end def dir_entries(rel_path) - subtree = if ['', '.'].include? rel_path.to_s + subtree = if ['', '.'].include?(rel_path.to_s) @tree else @tree[rel_path.to_s] ||= _auto_hash @tree[rel_path.to_s] end - subtree.transform_values do |values| + subtree.each_with_object({}) do |(key, values), result| # only get data for file entries - values.key?(:mtime) ? values : {} + result[key] = values.has_key?(:mtime) ? values : {} end end From 015d12977354287eda95f110e852e76cc2a383f5 Mon Sep 17 00:00:00 2001 From: Colin Kelley Date: Mon, 29 Mar 2021 23:51:28 -0700 Subject: [PATCH 6/7] avoid Thread#name in ruby < 2.3 --- lib/listen/thread.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/listen/thread.rb b/lib/listen/thread.rb index a1e6b3b6..f93fb959 100644 --- a/lib/listen/thread.rb +++ b/lib/listen/thread.rb @@ -17,7 +17,7 @@ def new(name, &block) ::Thread.new do rescue_and_log(thread_name, caller_stack: caller_stack, &block) end.tap do |thread| - thread.name = thread_name + thread.name = thread_name unless RUBY_VERSION[/\d+\.\d+/].to_f < 2.3 end end # rubocop:enable Style/MultilineBlockChain From 1a35031729d73afd2e1eed6e90c612dc5b1d6c81 Mon Sep 17 00:00:00 2001 From: Colin Kelley Date: Mon, 29 Mar 2021 23:51:53 -0700 Subject: [PATCH 7/7] avoid String#+ in ruby < 2.3 --- lib/listen/thread.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/listen/thread.rb b/lib/listen/thread.rb index f93fb959..f2196f8e 100644 --- a/lib/listen/thread.rb +++ b/lib/listen/thread.rb @@ -41,7 +41,12 @@ def _log_exception(exception, thread_name, caller_stack: nil) end def _exception_with_causes(exception) - result = +"#{exception.class}: #{exception}" + result = + if RUBY_VERSION[/\d+\.\d+/].to_f < 2.3 + "#{exception.class}: #{exception}" + else + +"#{exception.class}: #{exception}" + end if exception.cause result << "\n" result << "--- Caused by: ---\n"