summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0xAB <0xAB@protonmail.com>2017-08-23 03:46:29 +0100
committer0xAB <0xAB@protonmail.com>2017-08-23 03:46:29 +0100
commitbfc5e9a3640e4a6c08169dca24a53beefa8ce65e (patch)
treed397f130fafe4fb4ad0bc7fe18fe019edab79d58
parent35dc3a26b6315610b5f48bc886c614d9e69054ca (diff)
parent4a4ab2958c5364f5344364023865b5d0ec2c51f5 (diff)
downloadpry-extensible-prompts.tar.gz
Merge remote-tracking branch 'pry/master' into extensible-promptsextensible-prompts
-rw-r--r--.travis.yml3
-rw-r--r--CHANGELOG.md2
-rw-r--r--lib/pry/helpers/text.rb10
-rw-r--r--lib/pry/wrapped_module/candidate.rb10
-rw-r--r--spec/wrapped_module_spec.rb13
5 files changed, 34 insertions, 4 deletions
diff --git a/.travis.yml b/.travis.yml
index aaba3066..71ddd45c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,7 +5,7 @@ rvm:
- 2.1
- 2.2
- 2.3.1
- - 2.4
+ - 2.4.1
- ruby-head
- rbx-2
- jruby
@@ -21,6 +21,7 @@ matrix:
- rvm: ruby-head
- rvm: jruby-head
- rvm: rbx-2
+ - rvm: 2.4.1 # because of https://bugs.ruby-lang.org/issues/13537
notifications:
irc: "irc.freenode.org#pry"
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0a4c2081..1137a5d4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,8 @@
* Add `Pry::Prompt.add_prompt()`, `Pry::Prompt.get_prompt()`, and `Pry::Prompt.remove_prompt()`, for integrating custom prompts with Pry ([#1628](https://github.com/pry/pry/pull/1628))
* Add text helpers for background colors ([#1624](https://github.com/pry/pry/pull/1624))
* Fix string literal methods completion. ([#1590](https://github.com/pry/pry/pull/1590))
+* Make sure Pry::WrappedModule::Candidate#source_location returns non-nil value when `.name` has
+ been redefined on a Class/Module ([#1623](https://github.com/pry/pry/pull/1623))
* Add alias 'whereami[?!]+' for 'whereami' command. ([#1597](https://github.com/pry/pry/pull/1597))
* Improve Ruby 2.4 support ([#1611](https://github.com/pry/pry/pull/1611)):
* Deprecated constants are hidden from `ls` output by default, use the `-d` switch to see them.
diff --git a/lib/pry/helpers/text.rb b/lib/pry/helpers/text.rb
index 22aecccd..6c171da7 100644
--- a/lib/pry/helpers/text.rb
+++ b/lib/pry/helpers/text.rb
@@ -24,6 +24,16 @@ class Pry
define_method "bright_#{color}" do |text|
"\033[1;#{30+value}m#{text}\033[0m"
end
+
+ COLORS.each_pair do |bg_color, bg_value|
+ define_method "#{color}_on_#{bg_color}" do |text|
+ "\033[0;#{30 + value};#{40 + bg_value}m#{text}\033[0m"
+ end
+
+ define_method "bright_#{color}_on_#{bg_color}" do |text|
+ "\033[1;#{30 + value};#{40 + bg_value}m#{text}\033[0m"
+ end
+ end
end
# Remove any color codes from _text_.
diff --git a/lib/pry/wrapped_module/candidate.rb b/lib/pry/wrapped_module/candidate.rb
index 67ef1925..3481b2d0 100644
--- a/lib/pry/wrapped_module/candidate.rb
+++ b/lib/pry/wrapped_module/candidate.rb
@@ -97,9 +97,13 @@ class Pry
def class_regexes
mod_type_string = wrapped.class.to_s.downcase
- [/^\s*#{mod_type_string}\s+(?:(?:\w*)::)*?#{wrapped.name.split(/::/).last}/,
- /^\s*(::)?#{wrapped.name.split(/::/).last}\s*?=\s*?#{wrapped.class}/,
- /^\s*(::)?#{wrapped.name.split(/::/).last}\.(class|instance)_eval/]
+
+ # workaround for things that redefine Module.name - yes, they're out there.
+ wrapped_name = Pry::Helpers::BaseHelpers.safe_send wrapped, :name
+
+ [/^\s*#{mod_type_string}\s+(?:(?:\w*)::)*?#{wrapped_name.split(/::/).last}/,
+ /^\s*(::)?#{wrapped_name.split(/::/).last}\s*?=\s*?#{wrapped.class}/,
+ /^\s*(::)?#{wrapped_name.split(/::/).last}\.(class|instance)_eval/]
end
# This method is used by `Candidate#source_location` as a
diff --git a/spec/wrapped_module_spec.rb b/spec/wrapped_module_spec.rb
index b46d9cac..2482fd28 100644
--- a/spec/wrapped_module_spec.rb
+++ b/spec/wrapped_module_spec.rb
@@ -35,6 +35,19 @@ describe Pry::WrappedModule do
end
end
end
+
+ module ModuleNameOverride
+ def self.name; 'Not a good idea, but it happens in the wild.' end
+ end
+ end
+
+ describe 'overidden Module#name' do
+ specify '#source_location does not return nil' do
+ c = Pry::WrappedModule(Host::ModuleNameOverride).candidate(0)
+ expect(c.wrapped).to eq(Host::ModuleNameOverride)
+ expect(c.nonblank_name).to eq(Host::ModuleNameOverride.name)
+ expect(c.source_location).not_to be_nil
+ end
end
describe "number_of_candidates" do