From 273d4b02ef0aab176c754d674926d5eaaf5b0b32 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 26 Oct 2023 16:20:44 +0100 Subject: [PATCH] (bug) - Fix ruby 3.x incompatibility It was noted that this gem was failing spec tests when running on ruby 3.x and above. The root cause of this issue seemed to be the absolute_path property found on the Thread::Backtrace::Location class. Updating this to path allows spec tests to pass on both ruby 2.x and 3.x. Can confirm that when consumed by other tools, this also works as expected. Open to suggested changes and improvements. --- lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb | 2 +- lib/puppetfile-resolver/puppetfile/parser/r10k_eval/dsl.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb b/lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb index 56480ed..ebd8934 100644 --- a/lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb +++ b/lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb @@ -21,7 +21,7 @@ def self.parse(puppetfile_contents) rescue StandardError, LoadError => e # Find the originating error from within the puppetfile loc = e.backtrace_locations - .select { |item| item.absolute_path == PUPPETFILE_MONIKER } + .select { |item| item.path == PUPPETFILE_MONIKER } .first start_line_number = loc.nil? ? 0 : loc.lineno - 1 # Line numbers from ruby are base 1 end_line_number = loc.nil? ? puppetfile_contents.lines.count - 1 : loc.lineno - 1 # Line numbers from ruby are base 1 diff --git a/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/dsl.rb b/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/dsl.rb index 3f3d6e3..576df41 100644 --- a/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/dsl.rb +++ b/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/dsl.rb @@ -41,7 +41,7 @@ def method_missing(method_name, *_args) # rubocop:disable Style/MethodMissingSup def find_load_line_number loc = Kernel.caller_locations - .find { |call_loc| call_loc.absolute_path == ::PuppetfileResolver::Puppetfile::Parser::R10KEval::PUPPETFILE_MONIKER } + .find { |call_loc| call_loc.path == ::PuppetfileResolver::Puppetfile::Parser::R10KEval::PUPPETFILE_MONIKER } loc.nil? ? 0 : loc.lineno - 1 # Line numbers from ruby are base 1 end end