mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Pry::CodeObject: remove unnecessary 'target' parameter
Since we can access 'target' via _pry_.current_context * We also update a few files (code_collector/show_info) that need to be updated for this change
This commit is contained in:
parent
139a2a7a0a
commit
7ae55b3a8a
5 changed files with 47 additions and 29 deletions
|
@ -23,8 +23,8 @@ class Pry
|
|||
include Pry::Helpers::CommandHelpers
|
||||
|
||||
class << self
|
||||
def lookup(str, target, _pry_, options={})
|
||||
co = new(str, target, _pry_, options)
|
||||
def lookup(str, _pry_, options={})
|
||||
co = new(str, _pry_, options)
|
||||
|
||||
co.default_lookup || co.method_or_class_lookup ||
|
||||
co.command_lookup || co.empty_lookup
|
||||
|
@ -36,14 +36,14 @@ class Pry
|
|||
attr_accessor :pry
|
||||
attr_accessor :super_level
|
||||
|
||||
def initialize(str, target, _pry_, options={})
|
||||
def initialize(str, _pry_, options={})
|
||||
options = {
|
||||
:super => 0,
|
||||
}.merge!(options)
|
||||
|
||||
@str = str
|
||||
@target = target
|
||||
@pry = _pry_
|
||||
@target = _pry_.current_context
|
||||
@super_level = options[:super]
|
||||
end
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ class Pry
|
|||
#
|
||||
# @return [Pry::WrappedModule, Pry::Method, Pry::Command]
|
||||
def code_object
|
||||
Pry::CodeObject.lookup(obj_name, _pry_.current_context, _pry_, :super => opts[:super])
|
||||
Pry::CodeObject.lookup(obj_name, _pry_, :super => opts[:super])
|
||||
end
|
||||
|
||||
# Given a string and a range, return the `range` lines of that
|
||||
|
|
|
@ -9,7 +9,7 @@ class Pry
|
|||
BANNER
|
||||
|
||||
def process
|
||||
code_object = Pry::CodeObject.lookup(obj_name, target, _pry_)
|
||||
code_object = Pry::CodeObject.lookup(obj_name, _pry_)
|
||||
|
||||
check_for_reloadability(code_object)
|
||||
reload_code_object(code_object)
|
||||
|
|
|
@ -18,7 +18,7 @@ class Pry
|
|||
end
|
||||
|
||||
def process
|
||||
code_object = Pry::CodeObject.lookup(obj_name, target, _pry_, :super => opts[:super])
|
||||
code_object = Pry::CodeObject.lookup(obj_name, _pry_, :super => opts[:super])
|
||||
raise Pry::CommandError, "Couldn't locate #{obj_name}!" if !code_object
|
||||
|
||||
if show_all_modules?(code_object)
|
||||
|
|
|
@ -13,6 +13,9 @@ describe Pry::CodeObject do
|
|||
binding
|
||||
end
|
||||
end
|
||||
|
||||
@p = Pry.new
|
||||
@p.binding_stack = [binding]
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -20,20 +23,21 @@ describe Pry::CodeObject do
|
|||
end
|
||||
|
||||
it 'should lookup methods' do
|
||||
m = Pry::CodeObject.lookup("@obj.ziggy", binding, Pry.new)
|
||||
m = Pry::CodeObject.lookup("@obj.ziggy", @p)
|
||||
m.is_a?(Pry::Method).should == true
|
||||
m.name.to_sym.should == :ziggy
|
||||
end
|
||||
|
||||
it 'should lookup modules' do
|
||||
m = Pry::CodeObject.lookup("ClassyWassy", binding, Pry.new)
|
||||
m = Pry::CodeObject.lookup("ClassyWassy", @p)
|
||||
m.is_a?(Pry::WrappedModule).should == true
|
||||
m.source.should =~ /piggy/
|
||||
end
|
||||
|
||||
it 'should lookup procs' do
|
||||
my_proc = proc { :hello }
|
||||
m = Pry::CodeObject.lookup("my_proc", binding, Pry.new)
|
||||
@p.binding_stack = [binding]
|
||||
m = Pry::CodeObject.lookup("my_proc", @p)
|
||||
m.is_a?(Pry::Method).should == true
|
||||
m.source.should =~ /hello/
|
||||
end
|
||||
|
@ -41,13 +45,14 @@ describe Pry::CodeObject do
|
|||
describe 'commands lookup' do
|
||||
before do
|
||||
@p = Pry.new
|
||||
@p.binding_stack = [binding]
|
||||
end
|
||||
|
||||
it 'should return command class' do
|
||||
@p.commands.command "jeremy-jones" do
|
||||
"lobster"
|
||||
end
|
||||
m = Pry::CodeObject.lookup("jeremy-jones", binding, @p)
|
||||
m = Pry::CodeObject.lookup("jeremy-jones", @p)
|
||||
(m <= Pry::Command).should == true
|
||||
m.source.should =~ /lobster/
|
||||
end
|
||||
|
@ -69,7 +74,7 @@ describe Pry::CodeObject do
|
|||
|
||||
it 'should return Pry::ClassCommand class when looking up class command' do
|
||||
Pry.commands.add_command(LobsterLady)
|
||||
m = Pry::CodeObject.lookup("lobster-lady", binding, @p)
|
||||
m = Pry::CodeObject.lookup("lobster-lady", @p)
|
||||
(m <= Pry::ClassCommand).should == true
|
||||
m.source.should =~ /class LobsterLady/
|
||||
Pry.commands.delete("lobster-lady")
|
||||
|
@ -77,7 +82,7 @@ describe Pry::CodeObject do
|
|||
|
||||
it 'should return Pry::WrappedModule when looking up command class directly (as a class, not as a command)' do
|
||||
Pry.commands.add_command(LobsterLady)
|
||||
m = Pry::CodeObject.lookup("LobsterLady", binding, @p)
|
||||
m = Pry::CodeObject.lookup("LobsterLady", @p)
|
||||
m.is_a?(Pry::WrappedModule).should == true
|
||||
m.source.should =~ /class LobsterLady/
|
||||
Pry.commands.delete("lobster-lady")
|
||||
|
@ -88,13 +93,13 @@ describe Pry::CodeObject do
|
|||
@p.commands.command /jeremy-.*/, "", :listing => "jeremy-baby" do
|
||||
"lobster"
|
||||
end
|
||||
m = Pry::CodeObject.lookup("jeremy-baby", binding, @p)
|
||||
m = Pry::CodeObject.lookup("jeremy-baby", @p)
|
||||
(m <= Pry::Command).should == true
|
||||
m.source.should =~ /lobster/
|
||||
end
|
||||
|
||||
it 'finds nothing when passing nil as the first argument' do
|
||||
Pry::CodeObject.lookup(nil, binding, @p).should == nil
|
||||
Pry::CodeObject.lookup(nil, @p).should == nil
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -106,7 +111,8 @@ describe Pry::CodeObject do
|
|||
end
|
||||
end
|
||||
|
||||
m = Pry::CodeObject.lookup("o#princess_bubblegum", binding, Pry.new)
|
||||
@p.binding_stack = [binding]
|
||||
m = Pry::CodeObject.lookup("o#princess_bubblegum", @p)
|
||||
m.is_a?(Pry::Method).should == true
|
||||
m.source.should =~ /mathematic!/
|
||||
end
|
||||
|
@ -117,15 +123,16 @@ describe Pry::CodeObject do
|
|||
"4 realzies"
|
||||
end
|
||||
end
|
||||
|
||||
m = Pry::CodeObject.lookup("o.finn", binding, Pry.new)
|
||||
@p.binding_stack = [binding]
|
||||
m = Pry::CodeObject.lookup("o.finn", @p)
|
||||
m.is_a?(Pry::Method).should == true
|
||||
m.source.should =~ /4 realzies/
|
||||
end
|
||||
|
||||
it 'should lookup the class of an object (when given a variable)' do
|
||||
moddy = ClassyWassy.new
|
||||
m = Pry::CodeObject.lookup("moddy", binding, Pry.new)
|
||||
@p.binding_stack = [binding]
|
||||
m = Pry::CodeObject.lookup("moddy", @p)
|
||||
m.is_a?(Pry::WrappedModule).should == true
|
||||
m.source.should =~ /piggy/
|
||||
end
|
||||
|
@ -139,7 +146,8 @@ describe Pry::CodeObject do
|
|||
describe "infer module objects" do
|
||||
it 'should infer module object when binding self is a module' do
|
||||
["", nil].each do |v|
|
||||
m = Pry::CodeObject.lookup(v, @b1, Pry.new)
|
||||
@p.binding_stack = [@b1]
|
||||
m = Pry::CodeObject.lookup(v, @p)
|
||||
m.is_a?(Pry::WrappedModule).should == true
|
||||
m.name.should =~ /ClassyWassy/
|
||||
end
|
||||
|
@ -147,7 +155,8 @@ describe Pry::CodeObject do
|
|||
|
||||
it 'should infer module object when binding self is an instance' do
|
||||
["", nil].each do |v|
|
||||
m = Pry::CodeObject.lookup(v, @b2, Pry.new)
|
||||
@p.binding_stack = [@b2]
|
||||
m = Pry::CodeObject.lookup(v, @p)
|
||||
m.is_a?(Pry::WrappedModule).should == true
|
||||
m.name.should =~ /ClassyWassy/
|
||||
end
|
||||
|
@ -159,7 +168,8 @@ describe Pry::CodeObject do
|
|||
b = ClassyWassy.new.piggy
|
||||
|
||||
["", nil].each do |v|
|
||||
m = Pry::CodeObject.lookup(v, b, Pry.new)
|
||||
@p.binding_stack = [b]
|
||||
m = Pry::CodeObject.lookup(v, @p)
|
||||
m.is_a?(Pry::Method).should == true
|
||||
m.name.should =~ /piggy/
|
||||
end
|
||||
|
@ -172,6 +182,8 @@ describe Pry::CodeObject do
|
|||
before do
|
||||
class MyClassyWassy; end
|
||||
class CuteSubclass < MyClassyWassy; end
|
||||
@p = Pry.new
|
||||
@p.binding_stack = [binding]
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -180,13 +192,13 @@ describe Pry::CodeObject do
|
|||
end
|
||||
|
||||
it 'should lookup original class with :super => 0' do
|
||||
m = Pry::CodeObject.lookup("CuteSubclass", binding, Pry.new, :super => 0)
|
||||
m = Pry::CodeObject.lookup("CuteSubclass", @p, :super => 0)
|
||||
m.is_a?(Pry::WrappedModule).should == true
|
||||
m.wrapped.should == CuteSubclass
|
||||
end
|
||||
|
||||
it 'should lookup immediate super class with :super => 1' do
|
||||
m = Pry::CodeObject.lookup("CuteSubclass", binding, Pry.new, :super => 1)
|
||||
m = Pry::CodeObject.lookup("CuteSubclass", @p, :super => 1)
|
||||
m.is_a?(Pry::WrappedModule).should == true
|
||||
m.wrapped.should == MyClassyWassy
|
||||
end
|
||||
|
@ -196,7 +208,8 @@ describe Pry::CodeObject do
|
|||
p.commands.command "jeremy-jones" do
|
||||
"lobster"
|
||||
end
|
||||
m = Pry::CodeObject.lookup("jeremy-jones", binding, p, :super => 10)
|
||||
p.binding_stack = [binding]
|
||||
m = Pry::CodeObject.lookup("jeremy-jones", p, :super => 10)
|
||||
m.source.should =~ /lobster/
|
||||
end
|
||||
end
|
||||
|
@ -221,6 +234,9 @@ describe Pry::CodeObject do
|
|||
:ducky
|
||||
end
|
||||
end
|
||||
|
||||
@p = Pry.new
|
||||
@p.binding_stack = [binding]
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -229,13 +245,13 @@ describe Pry::CodeObject do
|
|||
end
|
||||
|
||||
it 'should look up methods before classes (at top-level)' do
|
||||
m = Pry::CodeObject.lookup("ClassyWassy", binding, Pry.new)
|
||||
m = Pry::CodeObject.lookup("ClassyWassy", @p)
|
||||
m.is_a?(Pry::Method).should == true
|
||||
m.source.should =~ /ducky/
|
||||
end
|
||||
|
||||
it 'should look up classes before methods when namespaced' do
|
||||
m = Pry::CodeObject.lookup("ClassyWassy::Puff", binding, Pry.new)
|
||||
m = Pry::CodeObject.lookup("ClassyWassy::Puff", @p)
|
||||
m.is_a?(Pry::WrappedModule).should == true
|
||||
m.source.should =~ /tiggy/
|
||||
end
|
||||
|
@ -243,7 +259,8 @@ describe Pry::CodeObject do
|
|||
it 'should look up locals before methods' do
|
||||
b = Pry.binding_for(ClassyWassy)
|
||||
b.eval("piggy = Puff.new")
|
||||
o = Pry::CodeObject.lookup("piggy", b, Pry.new)
|
||||
@p.binding_stack = [b]
|
||||
o = Pry::CodeObject.lookup("piggy", @p)
|
||||
o.is_a?(Pry::WrappedModule).should == true
|
||||
end
|
||||
|
||||
|
@ -251,7 +268,8 @@ describe Pry::CodeObject do
|
|||
# just falls through to co.method_or_class
|
||||
it 'should look up classes before locals' do
|
||||
c = ClassyWassy
|
||||
o = Pry::CodeObject.lookup("c", binding, Pry.new)
|
||||
@p.binding_stack = [binding]
|
||||
o = Pry::CodeObject.lookup("c", @p)
|
||||
o.is_a?(Pry::WrappedModule).should == true
|
||||
o.wrapped.should == ClassyWassy
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue