From 451a4d72dd2d86f952906cece3cfe314d4d707f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Tue, 24 Jan 2017 17:14:46 +0100 Subject: [PATCH] Fix Ruby 2.4 compatibility. --- ...-String-pretty_print-in-ColorPrinter.patch | 32 ++++++++++++++ ...-unified-into-Integer-since-Ruby-2.4.patch | 32 ++++++++++++++ ...mplementation-of-BasicObject-inspect.patch | 44 +++++++++++++++++++ rubygem-pry.spec | 16 ++++++- 4 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 pry-0.10.4-Avoid-calling-Ruby-2.4-String-pretty_print-in-ColorPrinter.patch create mode 100644 pry-0.10.4-Fixnum-and-Bignum-are-unified-into-Integer-since-Ruby-2.4.patch create mode 100644 pry-0.10.4-support-custom-implementation-of-BasicObject-inspect.patch diff --git a/pry-0.10.4-Avoid-calling-Ruby-2.4-String-pretty_print-in-ColorPrinter.patch b/pry-0.10.4-Avoid-calling-Ruby-2.4-String-pretty_print-in-ColorPrinter.patch new file mode 100644 index 0000000..1fc8465 --- /dev/null +++ b/pry-0.10.4-Avoid-calling-Ruby-2.4-String-pretty_print-in-ColorPrinter.patch @@ -0,0 +1,32 @@ +From ff6263fd9ddf2d689ecfa8fa7eb1216bfad441a8 Mon Sep 17 00:00:00 2001 +From: Akira Matsuda +Date: Thu, 8 Dec 2016 03:51:38 +0900 +Subject: [PATCH] Avoid calling Ruby 2.4+ String#pretty_print in ColorPrinter + +Ruby 2.4+ defines String's own pretty_print that prints multiline Strings prettier +see: https://bugs.ruby-lang.org/issues/12664 + +fixes #1585 +--- + lib/pry/color_printer.rb | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/lib/pry/color_printer.rb b/lib/pry/color_printer.rb +index 48bcc1a..ce52b8d 100644 +--- a/lib/pry/color_printer.rb ++++ b/lib/pry/color_printer.rb +@@ -31,7 +31,13 @@ def text(str, width = str.length) + end + + def pp(obj) +- super ++ if String === obj ++ # Avoid calling Ruby 2.4+ String#pretty_print that prints multiline ++ # Strings prettier ++ Object.instance_method(:pretty_print).bind(obj).call ++ else ++ super ++ end + rescue => e + raise if e.is_a? Pry::Pager::StopPaging + begin diff --git a/pry-0.10.4-Fixnum-and-Bignum-are-unified-into-Integer-since-Ruby-2.4.patch b/pry-0.10.4-Fixnum-and-Bignum-are-unified-into-Integer-since-Ruby-2.4.patch new file mode 100644 index 0000000..63e5e24 --- /dev/null +++ b/pry-0.10.4-Fixnum-and-Bignum-are-unified-into-Integer-since-Ruby-2.4.patch @@ -0,0 +1,32 @@ +From 866ea0b9f983229f53997dd9c87212281683f3df Mon Sep 17 00:00:00 2001 +From: Akira Matsuda +Date: Thu, 8 Dec 2016 03:54:12 +0900 +Subject: [PATCH] Fixnum and Bignum are unified into Integer since Ruby 2.4 + +see: https://bugs.ruby-lang.org/issues/12005 +--- + spec/commands/ls_spec.rb | 11 +++++++++-- + 1 file changed, 9 insertions(+), 2 deletions(-) + +diff --git a/spec/commands/ls_spec.rb b/spec/commands/ls_spec.rb +index 0fc489b..d89fcc2 100644 +--- a/spec/commands/ls_spec.rb ++++ b/spec/commands/ls_spec.rb +@@ -48,8 +48,15 @@ + end + + describe "immediates" do +- it "should work on Fixnum" do +- pry_eval("ls 5").should =~ /Fixnum#methods:.*modulo/m ++ # Ruby 2.4+ ++ if 5.class.name == 'Integer' ++ it "should work on Integer" do ++ expect(pry_eval("ls 5")).to match(/Integer#methods:.*modulo/m) ++ end ++ else ++ it "should work on Fixnum" do ++ expect(pry_eval("ls 5")).to match(/Fixnum#methods:.*modulo/m) ++ end + end + end + diff --git a/pry-0.10.4-support-custom-implementation-of-BasicObject-inspect.patch b/pry-0.10.4-support-custom-implementation-of-BasicObject-inspect.patch new file mode 100644 index 0000000..e745186 --- /dev/null +++ b/pry-0.10.4-support-custom-implementation-of-BasicObject-inspect.patch @@ -0,0 +1,44 @@ +From 81fc96f73bdb26901c75838262779002bf6e14c5 Mon Sep 17 00:00:00 2001 +From: rpag +Date: Mon, 12 Jan 2015 20:18:59 +0000 +Subject: [PATCH] support custom implementation of BasicObject#inspect. + +If BasicObject or a subclass of BasicObject implements #inspect, +we will try to use its return value as output but if that fails, +we'll fallback on __id__. + +fixes #1341 +--- + lib/pry/color_printer.rb | 19 +++++++++++-------- + 1 file changed, 11 insertions(+), 8 deletions(-) + +diff --git a/lib/pry/color_printer.rb b/lib/pry/color_printer.rb +index 218a821..48bcc1a 100644 +--- a/lib/pry/color_printer.rb ++++ b/lib/pry/color_printer.rb +@@ -34,14 +34,17 @@ def pp(obj) + super + rescue => e + raise if e.is_a? Pry::Pager::StopPaging +- +- # Read the class name off of the singleton class to provide a default +- # inspect. +- singleton = class << obj; self; end +- ancestors = Pry::Method.safe_send(singleton, :ancestors) +- klass = ancestors.reject { |k| k == singleton }.first +- obj_id = obj.__id__.to_s(16) rescue 0 +- str = "#<#{klass}:0x#{obj_id}>" ++ begin ++ str = obj.inspect ++ rescue Exception ++ # Read the class name off of the singleton class to provide a default ++ # inspect. ++ singleton = class << obj; self; end ++ ancestors = Pry::Method.safe_send(singleton, :ancestors) ++ klass = ancestors.reject { |k| k == singleton }.first ++ obj_id = obj.__id__.to_s(16) rescue 0 ++ str = "#<#{klass}:0x#{obj_id}>" ++ end + + text highlight_object_literal(str) + end diff --git a/rubygem-pry.spec b/rubygem-pry.spec index e9cb052..7b61814 100644 --- a/rubygem-pry.spec +++ b/rubygem-pry.spec @@ -2,7 +2,7 @@ Name: rubygem-%{gem_name} Version: 0.10.4 -Release: 1%{?dist} +Release: 2%{?dist} Summary: An IRB alternative and runtime developer console Group: Development/Languages License: MIT @@ -14,6 +14,11 @@ Source2: %{gem_name}-%{version}-tests.tar.xz # rm stray openstruct reference. Upstream at # https://github.com/pry/pry/commit/70942ad3b2d93e028fc3e8bfe1c6bd11ec79ffad Patch0: rubygem-pry-0.10.1-rm-openstruct.patch +# Fix Ruby 2.4 compatibility. +# https://github.com/pry/pry/pull/1586 +Patch1: pry-0.10.4-support-custom-implementation-of-BasicObject-inspect.patch +Patch2: pry-0.10.4-Avoid-calling-Ruby-2.4-String-pretty_print-in-ColorPrinter.patch +Patch3: pry-0.10.4-Fixnum-and-Bignum-are-unified-into-Integer-since-Ruby-2.4.patch %if 0%{?fc19} || 0%{?fc20} || 0%{?el7} Requires: ruby(release) Requires: ruby(rubygems) @@ -58,6 +63,9 @@ gem unpack %{SOURCE0} gem spec %{SOURCE0} -l --ruby > %{gem_name}.gemspec +%patch1 -p1 +%patch2 -p1 + %build gem build %{gem_name}.gemspec @@ -80,7 +88,8 @@ pushd .%{gem_instdir} tar xvf %{SOURCE2} # rm stray openstruct reference -patch -p1 < %{PATCH0} +cat %{PATCH0} | patch -p1 +cat %{PATCH3} | patch -p1 # Rakefile is used by editor test. touch Rakefile @@ -112,6 +121,9 @@ popd %doc %{gem_instdir}/README.md %changelog +* Tue Jan 24 2017 Vít Ondruch - 0.10.4-2 +- Fix Ruby 2.4 compatibility. + * Fri Oct 14 2016 Vít Ondruch - 0.10.4-1 - Update to Pry 0.10.4.