mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Thread.current -> Pry.current
This commit is contained in:
parent
0531b8a7bd
commit
5e3a3f068b
6 changed files with 21 additions and 21 deletions
|
@ -94,8 +94,8 @@ class Pry
|
||||||
# @param [String] source The source to wrap
|
# @param [String] source The source to wrap
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def wrap_for_owner(source)
|
def wrap_for_owner(source)
|
||||||
Thread.current[:__pry_owner__] = code_object.owner
|
Pry.current[:pry_owner] = code_object.owner
|
||||||
source = "Thread.current[:__pry_owner__].class_eval do\n#{source}\nend"
|
source = "Pry.current[:pry_owner].class_eval do\n#{source}\nend"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update the new source code to have the correct Module.nesting.
|
# Update the new source code to have the correct Module.nesting.
|
||||||
|
|
|
@ -10,17 +10,17 @@ class Pry
|
||||||
start
|
start
|
||||||
end
|
end
|
||||||
|
|
||||||
Pry.th[:pry] = pry
|
Pry.current[:pry] = pry
|
||||||
proc{ |*a| Bond.agent.call(*a) }
|
proc{ |*a| Bond.agent.call(*a) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.start
|
def self.start
|
||||||
Bond.start(:eval_binding => lambda{ Pry.th[:pry].current_context })
|
Bond.start(:eval_binding => lambda{ Pry.current[:pry].current_context })
|
||||||
Bond.complete(:on => /\A/) do |input|
|
Bond.complete(:on => /\A/) do |input|
|
||||||
Pry.commands.complete(input.line,
|
Pry.commands.complete(input.line,
|
||||||
:pry_instance => Pry.th[:pry],
|
:pry_instance => Pry.current[:pry],
|
||||||
:target => Pry.th[:pry].current_context,
|
:target => Pry.current[:pry].current_context,
|
||||||
:command_set => Pry.th[:pry].commands)
|
:command_set => Pry.current[:pry].commands)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -124,12 +124,12 @@ class Pry
|
||||||
# @param [Binding] target The binding where the method is looked up.
|
# @param [Binding] target The binding where the method is looked up.
|
||||||
# @return [Method, UnboundMethod] The 'refined' method object.
|
# @return [Method, UnboundMethod] The 'refined' method object.
|
||||||
def lookup_method_via_binding(obj, method_name, method_type, target=TOPLEVEL_BINDING)
|
def lookup_method_via_binding(obj, method_name, method_type, target=TOPLEVEL_BINDING)
|
||||||
Pry.th[:obj] = obj
|
Pry.current[:obj] = obj
|
||||||
Pry.th[:name] = method_name
|
Pry.current[:name] = method_name
|
||||||
receiver = obj.is_a?(Module) ? "Module" : "Kernel"
|
receiver = obj.is_a?(Module) ? "Module" : "Kernel"
|
||||||
target.eval("::#{receiver}.instance_method(:#{method_type}).bind(Pry.th[:obj]).call(Pry.th[:name])")
|
target.eval("::#{receiver}.instance_method(:#{method_type}).bind(Pry.current[:obj]).call(Pry.current[:name])")
|
||||||
ensure
|
ensure
|
||||||
Pry.th[:obj] = Pry.th[:name] = nil
|
Pry.current[:obj] = Pry.current[:name] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Given a `Class` or `Module` and the name of a method, try to
|
# Given a `Class` or `Module` and the name of a method, try to
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Pry
|
||||||
LOCAL_RC_FILE = "./.pryrc"
|
LOCAL_RC_FILE = "./.pryrc"
|
||||||
|
|
||||||
# @return [Hash] Pry's `Thread.current` hash
|
# @return [Hash] Pry's `Thread.current` hash
|
||||||
def self.th
|
def self.current
|
||||||
Thread.current[:__pry__] ||= {}
|
Thread.current[:__pry__] ||= {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -145,10 +145,10 @@ class Pry
|
||||||
# @param [Binding] b The binding to set the local on.
|
# @param [Binding] b The binding to set the local on.
|
||||||
# @return [Object] The value the local was set to.
|
# @return [Object] The value the local was set to.
|
||||||
def inject_local(name, value, b)
|
def inject_local(name, value, b)
|
||||||
Thread.current[:__pry_local__] = value.is_a?(Proc) ? value.call : value
|
Pry.current[:pry_local] = value.is_a?(Proc) ? value.call : value
|
||||||
b.eval("#{name} = ::Thread.current[:__pry_local__]")
|
b.eval("#{name} = ::Pry.current[:pry_local]")
|
||||||
ensure
|
ensure
|
||||||
Thread.current[:__pry_local__] = nil
|
Pry.current[:pry_local] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Integer] The maximum amount of objects remembered by the inp and
|
# @return [Integer] The maximum amount of objects remembered by the inp and
|
||||||
|
@ -447,7 +447,7 @@ class Pry
|
||||||
})
|
})
|
||||||
|
|
||||||
# set a temporary (just so we can inject the value we want into eval_string)
|
# set a temporary (just so we can inject the value we want into eval_string)
|
||||||
Thread.current[:__pry_cmd_result__] = result
|
Pry.current[:pry_cmd_result] = result
|
||||||
|
|
||||||
# note that `result` wraps the result of command processing; if a
|
# note that `result` wraps the result of command processing; if a
|
||||||
# command was matched and invoked then `result.command?` returns true,
|
# command was matched and invoked then `result.command?` returns true,
|
||||||
|
@ -457,7 +457,7 @@ class Pry
|
||||||
# the command that was invoked was non-void (had a return value) and so we make
|
# the command that was invoked was non-void (had a return value) and so we make
|
||||||
# the value of the current expression equal to the return value
|
# the value of the current expression equal to the return value
|
||||||
# of the command.
|
# of the command.
|
||||||
eval_string.replace "Thread.current[:__pry_cmd_result__].retval\n"
|
eval_string.replace "::Pry.current[:pry_cmd_result].retval\n"
|
||||||
end
|
end
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
|
|
|
@ -29,10 +29,10 @@ module PryTestHelpers
|
||||||
|
|
||||||
# inject a variable into a binding
|
# inject a variable into a binding
|
||||||
def inject_var(name, value, b)
|
def inject_var(name, value, b)
|
||||||
Thread.current[:__pry_local__] = value
|
Pry.current[:pry_local] = value
|
||||||
b.eval("#{name} = Thread.current[:__pry_local__]")
|
b.eval("#{name} = ::Pry.current[:pry_local]")
|
||||||
ensure
|
ensure
|
||||||
Thread.current[:__pry_local__] = nil
|
Pry.current[:pry_local] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def constant_scope(*names)
|
def constant_scope(*names)
|
||||||
|
@ -165,7 +165,7 @@ class PryTester
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def last_command_result
|
def last_command_result
|
||||||
result = Thread.current[:__pry_cmd_result__]
|
result = Pry.current[:pry_cmd_result]
|
||||||
result.retval if result
|
result.retval if result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue