pry 0.9.8.2 → 0.9.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/README.markdown +20 -13
- data/Rakefile +1 -1
- data/lib/pry.rb +1 -2
- data/lib/pry/command.rb +88 -2
- data/lib/pry/command_set.rb +15 -85
- data/lib/pry/commands.rb +12 -8
- data/lib/pry/default_commands/cd.rb +58 -0
- data/lib/pry/default_commands/commands.rb +62 -0
- data/lib/pry/default_commands/context.rb +48 -165
- data/lib/pry/default_commands/editing.rb +385 -0
- data/lib/pry/default_commands/help.rb +127 -0
- data/lib/pry/default_commands/hist.rb +116 -0
- data/lib/pry/default_commands/{shell.rb → input_and_output.rb} +137 -15
- data/lib/pry/default_commands/introspection.rb +79 -232
- data/lib/pry/default_commands/ls.rb +4 -2
- data/lib/pry/default_commands/{basic.rb → misc.rb} +1 -14
- data/lib/pry/default_commands/navigating_pry.rb +114 -0
- data/lib/pry/helpers/base_helpers.rb +15 -3
- data/lib/pry/helpers/command_helpers.rb +16 -0
- data/lib/pry/history.rb +12 -4
- data/lib/pry/method.rb +2 -2
- data/lib/pry/pry_class.rb +7 -1
- data/lib/pry/pry_instance.rb +6 -0
- data/lib/pry/rbx_path.rb +6 -18
- data/lib/pry/version.rb +1 -1
- data/pry.gemspec +8 -8
- data/test/helper.rb +8 -0
- data/test/test_command.rb +256 -2
- data/test/test_command_integration.rb +2 -13
- data/test/test_command_set.rb +13 -23
- data/test/test_default_commands/test_help.rb +57 -0
- data/test/test_default_commands/test_introspection.rb +23 -0
- data/test/test_pry.rb +11 -0
- metadata +13 -9
- data/lib/pry/default_commands/documentation.rb +0 -209
- data/lib/pry/default_commands/input.rb +0 -247
- data/test/test_default_commands.rb +0 -58
@@ -3,8 +3,10 @@ class Pry
|
|
3
3
|
|
4
4
|
Ls = Pry::CommandSet.new do
|
5
5
|
|
6
|
-
create_command "ls","Show the list of vars and methods in the current scope.
|
7
|
-
|
6
|
+
create_command "ls","Show the list of vars and methods in the current scope.",
|
7
|
+
:shellwords => false, :interpolate => false do
|
8
|
+
|
9
|
+
group "Context"
|
8
10
|
|
9
11
|
def options(opt)
|
10
12
|
opt.banner unindent <<-USAGE
|
@@ -1,7 +1,6 @@
|
|
1
1
|
class Pry
|
2
2
|
module DefaultCommands
|
3
|
-
|
4
|
-
Basic = Pry::CommandSet.new do
|
3
|
+
Misc = Pry::CommandSet.new do
|
5
4
|
command "toggle-color", "Toggle syntax highlighting." do
|
6
5
|
Pry.color = !Pry.color
|
7
6
|
output.puts "Syntax highlighting #{Pry.color ? "on" : "off"}"
|
@@ -20,13 +19,6 @@ class Pry
|
|
20
19
|
output.puts "Pry version: #{Pry::VERSION} on Ruby #{RUBY_VERSION}."
|
21
20
|
end
|
22
21
|
|
23
|
-
command "import-set", "Import a command set" do |command_set_name|
|
24
|
-
raise CommandError, "Provide a command set name" if command_set.nil?
|
25
|
-
|
26
|
-
set = target.eval(arg_string)
|
27
|
-
_pry_.commands.import set
|
28
|
-
end
|
29
|
-
|
30
22
|
command "reload-method", "Reload the source file that contains the specified method" do |meth_name|
|
31
23
|
meth = get_method_or_raise(meth_name, target, {}, :omit_help)
|
32
24
|
|
@@ -45,11 +37,6 @@ class Pry
|
|
45
37
|
args.each { |file_name| load File.expand_path(file_name) }
|
46
38
|
end
|
47
39
|
|
48
|
-
command "reset", "Reset the REPL to a clean state." do
|
49
|
-
output.puts "Pry reset."
|
50
|
-
exec "pry"
|
51
|
-
end
|
52
40
|
end
|
53
|
-
|
54
41
|
end
|
55
42
|
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
class Pry
|
2
|
+
module DefaultCommands
|
3
|
+
|
4
|
+
NavigatingPry = Pry::CommandSet.new do
|
5
|
+
command "switch-to", "Start a new sub-session on a binding in the current stack (numbered by nesting)." do |selection|
|
6
|
+
selection = selection.to_i
|
7
|
+
|
8
|
+
if selection < 0 || selection > _pry_.binding_stack.size - 1
|
9
|
+
raise CommandError, "Invalid binding index #{selection} - use `nesting` command to view valid indices."
|
10
|
+
else
|
11
|
+
Pry.start(_pry_.binding_stack[selection])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
command "nesting", "Show nesting information." do
|
16
|
+
output.puts "Nesting status:"
|
17
|
+
output.puts "--"
|
18
|
+
_pry_.binding_stack.each_with_index do |obj, level|
|
19
|
+
if level == 0
|
20
|
+
output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))} (Pry top level)"
|
21
|
+
else
|
22
|
+
output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
command "jump-to", "Jump to a binding further up the stack, popping all bindings below." do |break_level|
|
28
|
+
break_level = break_level.to_i
|
29
|
+
nesting_level = _pry_.binding_stack.size - 1
|
30
|
+
|
31
|
+
case break_level
|
32
|
+
when nesting_level
|
33
|
+
output.puts "Already at nesting level #{nesting_level}"
|
34
|
+
when (0...nesting_level)
|
35
|
+
_pry_.binding_stack.slice!(break_level + 1, _pry_.binding_stack.size)
|
36
|
+
|
37
|
+
else
|
38
|
+
max_nest_level = nesting_level - 1
|
39
|
+
output.puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{break_level}."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
command "exit-all", "End the current Pry session (popping all bindings) and returning to caller. Accepts optional return value. Aliases: !!@" do
|
44
|
+
# clear the binding stack
|
45
|
+
_pry_.binding_stack.clear
|
46
|
+
|
47
|
+
# break out of the repl loop
|
48
|
+
throw(:breakout, target.eval(arg_string))
|
49
|
+
end
|
50
|
+
|
51
|
+
alias_command "!!@", "exit-all"
|
52
|
+
|
53
|
+
create_command "exit" do
|
54
|
+
description "Pop the previous binding (does NOT exit program). Aliases: quit"
|
55
|
+
|
56
|
+
banner <<-BANNER
|
57
|
+
Usage: exit [OPTIONS] [--help]
|
58
|
+
Aliases: quit
|
59
|
+
|
60
|
+
It can be useful to exit a context with a user-provided value. For
|
61
|
+
instance an exit value can be used to determine program flow.
|
62
|
+
|
63
|
+
e.g: `exit "pry this"`
|
64
|
+
e.g: `exit`
|
65
|
+
|
66
|
+
https://github.com/pry/pry/wiki/State-navigation#wiki-Exit_with_value
|
67
|
+
BANNER
|
68
|
+
|
69
|
+
command_options(
|
70
|
+
:keep_retval => true
|
71
|
+
)
|
72
|
+
|
73
|
+
def process
|
74
|
+
if _pry_.binding_stack.one?
|
75
|
+
# when breaking out of top-level then behave like `exit-all`
|
76
|
+
process_exit_all
|
77
|
+
else
|
78
|
+
# otherwise just pop a binding and return user supplied value
|
79
|
+
process_pop_and_return
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def process_exit_all
|
84
|
+
_pry_.binding_stack.clear
|
85
|
+
throw(:breakout, target.eval(arg_string))
|
86
|
+
end
|
87
|
+
|
88
|
+
def process_pop_and_return
|
89
|
+
popped_object = _pry_.binding_stack.pop.eval('self')
|
90
|
+
|
91
|
+
# return a user-specified value if given otherwise return the object
|
92
|
+
return target.eval(arg_string) unless arg_string.empty?
|
93
|
+
popped_object
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
alias_command "quit", "exit"
|
98
|
+
|
99
|
+
command "exit-program", "End the current program. Aliases: quit-program, !!!" do
|
100
|
+
Pry.save_history if Pry.config.history.should_save
|
101
|
+
Kernel.exit target.eval(arg_string).to_i
|
102
|
+
end
|
103
|
+
|
104
|
+
alias_command "quit-program", "exit-program"
|
105
|
+
alias_command "!!!", "exit-program"
|
106
|
+
|
107
|
+
command "!pry", "Start a Pry session on current self; this even works mid multi-line expression." do
|
108
|
+
target.pry
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
@@ -126,15 +126,27 @@ class Pry
|
|
126
126
|
# Try to use `less` for paging, if it fails then use
|
127
127
|
# simple_pager. Also do not page if Pry.pager is falsey
|
128
128
|
# FIXME! Another JRuby hack
|
129
|
-
def stagger_output(text,
|
129
|
+
def stagger_output(text, out = nil)
|
130
|
+
out ||= case
|
131
|
+
when respond_to?(:output)
|
132
|
+
# Mixin.
|
133
|
+
output
|
134
|
+
when Pry.respond_to?(:output)
|
135
|
+
# Parent.
|
136
|
+
Pry.output
|
137
|
+
else
|
138
|
+
# Sys.
|
139
|
+
$stdout
|
140
|
+
end
|
141
|
+
|
130
142
|
if text.lines.count < page_size || !Pry.pager
|
131
|
-
|
143
|
+
out.puts text
|
132
144
|
return
|
133
145
|
end
|
134
146
|
|
135
147
|
# FIXME! Another JRuby hack
|
136
148
|
if jruby?
|
137
|
-
simple_pager(text,
|
149
|
+
simple_pager(text, out)
|
138
150
|
else
|
139
151
|
lesspipe { |less| less.puts text }
|
140
152
|
end
|
@@ -23,6 +23,22 @@ class Pry
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
# Return the file and line for a Binding.
|
27
|
+
# @param [Binding] target The binding
|
28
|
+
# @return [Array] The file and line
|
29
|
+
def file_and_line_from_binding(target)
|
30
|
+
file = target.eval('__FILE__')
|
31
|
+
line_num = target.eval('__LINE__')
|
32
|
+
if rbx?
|
33
|
+
if !target.instance_variable_defined?(:@__actual_file__)
|
34
|
+
target.instance_variable_set(:@__actual_file__, RbxPath.convert_path_to_full(target.variables.method.file.to_s))
|
35
|
+
end
|
36
|
+
file = target.instance_variable_get(:@__actual_file__).to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
[file, line_num]
|
40
|
+
end
|
41
|
+
|
26
42
|
def get_method_or_raise(name, target, opts={}, omit_help=false)
|
27
43
|
meth = Pry::Method.from_str(name, target, opts)
|
28
44
|
|
data/lib/pry/history.rb
CHANGED
@@ -70,8 +70,14 @@ class Pry
|
|
70
70
|
def read_from_file
|
71
71
|
history_file = File.expand_path(Pry.config.history.file)
|
72
72
|
|
73
|
-
|
74
|
-
File.
|
73
|
+
begin
|
74
|
+
if File.exists?(history_file)
|
75
|
+
File.foreach(history_file) { |line| yield(line) }
|
76
|
+
end
|
77
|
+
rescue => error
|
78
|
+
unless error.message.empty?
|
79
|
+
warn "History file not loaded, received an error: #{error.message}"
|
80
|
+
end
|
75
81
|
end
|
76
82
|
end
|
77
83
|
|
@@ -80,8 +86,10 @@ class Pry
|
|
80
86
|
def write_to_file(lines)
|
81
87
|
history_file = File.expand_path(Pry.config.history.file)
|
82
88
|
|
83
|
-
File.
|
84
|
-
|
89
|
+
if File.writable?(history_file)
|
90
|
+
File.open(history_file, 'a') do |f|
|
91
|
+
lines.each { |ln| f.puts ln }
|
92
|
+
end
|
85
93
|
end
|
86
94
|
end
|
87
95
|
|
data/lib/pry/method.rb
CHANGED
@@ -109,7 +109,7 @@ class Pry
|
|
109
109
|
# @param [String] name
|
110
110
|
# @return [Pry::Method, nil]
|
111
111
|
def from_class(klass, name)
|
112
|
-
new(klass
|
112
|
+
new(safe_send(klass, :instance_method, name)) rescue nil
|
113
113
|
end
|
114
114
|
alias from_module from_class
|
115
115
|
|
@@ -121,7 +121,7 @@ class Pry
|
|
121
121
|
# @param [String] name
|
122
122
|
# @return [Pry::Method, nil]
|
123
123
|
def from_obj(obj, name)
|
124
|
-
new(obj
|
124
|
+
new(safe_send(obj, :method, name)) rescue nil
|
125
125
|
end
|
126
126
|
|
127
127
|
# Get all of the instance methods of a `Class` or `Module`
|
data/lib/pry/pry_class.rb
CHANGED
@@ -249,7 +249,13 @@ class Pry
|
|
249
249
|
config.history ||= OpenStruct.new
|
250
250
|
config.history.should_save = true
|
251
251
|
config.history.should_load = true
|
252
|
-
config.history.file = File.expand_path("~/.pry_history")
|
252
|
+
config.history.file = File.expand_path("~/.pry_history") rescue nil
|
253
|
+
|
254
|
+
if config.history.file.nil?
|
255
|
+
config.should_load_rc = false
|
256
|
+
config.history.should_save = false
|
257
|
+
config.history.should_load = false
|
258
|
+
end
|
253
259
|
|
254
260
|
config.control_d_handler = DEFAULT_CONTROL_D_HANDLER
|
255
261
|
|
data/lib/pry/pry_instance.rb
CHANGED
@@ -79,6 +79,12 @@ class Pry
|
|
79
79
|
true
|
80
80
|
end
|
81
81
|
|
82
|
+
# The currently active `Binding`.
|
83
|
+
# @return [Binding] The currently active `Binding` for the session.
|
84
|
+
def current_context
|
85
|
+
binding_stack.last
|
86
|
+
end
|
87
|
+
|
82
88
|
# The current prompt.
|
83
89
|
# This is the prompt at the top of the prompt stack.
|
84
90
|
#
|
data/lib/pry/rbx_path.rb
CHANGED
@@ -2,33 +2,21 @@ class Pry
|
|
2
2
|
module RbxPath
|
3
3
|
module_function
|
4
4
|
def is_core_path?(path)
|
5
|
-
path.start_with?("kernel")
|
5
|
+
path.start_with?("kernel") || path.start_with?("lib")
|
6
6
|
end
|
7
7
|
|
8
8
|
def convert_path_to_full(path)
|
9
|
-
if
|
10
|
-
|
9
|
+
if path.start_with?("kernel")
|
10
|
+
File.join File.dirname(Rubinius::KERNEL_PATH), path
|
11
|
+
elsif path.start_with?("lib")
|
12
|
+
File.join File.dirname(Rubinius::LIB_PATH), path
|
11
13
|
else
|
12
|
-
|
14
|
+
path
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
18
|
def rvm_ruby?(path)
|
17
19
|
!!(path =~ /\.rvm/)
|
18
20
|
end
|
19
|
-
|
20
|
-
def rvm_convert_path_to_full(path)
|
21
|
-
ruby_name = File.dirname(Rubinius::BIN_PATH).split("/").last
|
22
|
-
source_path = File.join(File.dirname(File.dirname(File.dirname(Rubinius::BIN_PATH))), "src", ruby_name)
|
23
|
-
file_name = File.join(source_path, path)
|
24
|
-
raise "Cannot find rbx core source" if !File.exists?(file_name)
|
25
|
-
file_name
|
26
|
-
end
|
27
|
-
|
28
|
-
def std_convert_path_to_full(path)
|
29
|
-
file_name = File.join(Rubinius::BIN_PATH, "..", path)
|
30
|
-
raise "Cannot find rbx core source" if !File.exists?(file_name)
|
31
|
-
file_name
|
32
|
-
end
|
33
21
|
end
|
34
22
|
end
|
data/lib/pry/version.rb
CHANGED
data/pry.gemspec
CHANGED
@@ -2,20 +2,20 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "pry"
|
5
|
-
s.version = "0.9.8.
|
5
|
+
s.version = "0.9.8.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["John Mair (banisterfiend)"]
|
9
|
-
s.date = "2012-02
|
9
|
+
s.date = "2012-03-02"
|
10
10
|
s.description = "An IRB alternative and runtime developer console"
|
11
11
|
s.email = "jrmair@gmail.com"
|
12
12
|
s.executables = ["pry"]
|
13
|
-
s.files = [".document", ".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG", "CONTRIBUTORS", "Gemfile", "LICENSE", "README.markdown", "Rakefile", "TODO", "bin/pry", "examples/example_basic.rb", "examples/example_command_override.rb", "examples/example_commands.rb", "examples/example_hooks.rb", "examples/example_image_edit.rb", "examples/example_input.rb", "examples/example_input2.rb", "examples/example_output.rb", "examples/example_print.rb", "examples/example_prompt.rb", "examples/helper.rb", "lib/pry.rb", "lib/pry/cli.rb", "lib/pry/code.rb", "lib/pry/command.rb", "lib/pry/command_set.rb", "lib/pry/commands.rb", "lib/pry/completion.rb", "lib/pry/config.rb", "lib/pry/core_extensions.rb", "lib/pry/custom_completions.rb", "lib/pry/default_commands/
|
13
|
+
s.files = [".document", ".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG", "CONTRIBUTORS", "Gemfile", "LICENSE", "README.markdown", "Rakefile", "TODO", "bin/pry", "examples/example_basic.rb", "examples/example_command_override.rb", "examples/example_commands.rb", "examples/example_hooks.rb", "examples/example_image_edit.rb", "examples/example_input.rb", "examples/example_input2.rb", "examples/example_output.rb", "examples/example_print.rb", "examples/example_prompt.rb", "examples/helper.rb", "lib/pry.rb", "lib/pry/cli.rb", "lib/pry/code.rb", "lib/pry/command.rb", "lib/pry/command_set.rb", "lib/pry/commands.rb", "lib/pry/completion.rb", "lib/pry/config.rb", "lib/pry/core_extensions.rb", "lib/pry/custom_completions.rb", "lib/pry/default_commands/cd.rb", "lib/pry/default_commands/commands.rb", "lib/pry/default_commands/context.rb", "lib/pry/default_commands/easter_eggs.rb", "lib/pry/default_commands/editing.rb", "lib/pry/default_commands/gems.rb", "lib/pry/default_commands/help.rb", "lib/pry/default_commands/hist.rb", "lib/pry/default_commands/input_and_output.rb", "lib/pry/default_commands/introspection.rb", "lib/pry/default_commands/ls.rb", "lib/pry/default_commands/misc.rb", "lib/pry/default_commands/navigating_pry.rb", "lib/pry/extended_commands/experimental.rb", "lib/pry/helpers.rb", "lib/pry/helpers/base_helpers.rb", "lib/pry/helpers/command_helpers.rb", "lib/pry/helpers/options_helpers.rb", "lib/pry/helpers/text.rb", "lib/pry/history.rb", "lib/pry/history_array.rb", "lib/pry/hooks.rb", "lib/pry/indent.rb", "lib/pry/method.rb", "lib/pry/plugins.rb", "lib/pry/pry_class.rb", "lib/pry/pry_instance.rb", "lib/pry/rbx_method.rb", "lib/pry/rbx_path.rb", "lib/pry/version.rb", "lib/pry/wrapped_module.rb", "man/pry.1", "man/pry.1.html", "man/pry.1.ronn", "pry.gemspec", "test/helper.rb", "test/test_cli.rb", "test/test_code.rb", "test/test_command.rb", "test/test_command_helpers.rb", "test/test_command_integration.rb", "test/test_command_set.rb", "test/test_completion.rb", "test/test_default_commands/test_context.rb", "test/test_default_commands/test_documentation.rb", "test/test_default_commands/test_gems.rb", "test/test_default_commands/test_help.rb", "test/test_default_commands/test_input.rb", "test/test_default_commands/test_introspection.rb", "test/test_default_commands/test_ls.rb", "test/test_default_commands/test_shell.rb", "test/test_exception_whitelist.rb", "test/test_history_array.rb", "test/test_hooks.rb", "test/test_indent.rb", "test/test_input_stack.rb", "test/test_method.rb", "test/test_pry.rb", "test/test_pry_defaults.rb", "test/test_pry_history.rb", "test/test_pry_output.rb", "test/test_special_locals.rb", "test/test_syntax_checking.rb", "test/test_wrapped_module.rb", "test/testrc", "test/testrcbad", "wiki/Customizing-pry.md", "wiki/Home.md"]
|
14
14
|
s.homepage = "http://pry.github.com"
|
15
15
|
s.require_paths = ["lib"]
|
16
|
-
s.rubygems_version = "1.8.
|
16
|
+
s.rubygems_version = "1.8.16"
|
17
17
|
s.summary = "An IRB alternative and runtime developer console"
|
18
|
-
s.test_files = ["test/helper.rb", "test/test_cli.rb", "test/test_code.rb", "test/test_command.rb", "test/test_command_helpers.rb", "test/test_command_integration.rb", "test/test_command_set.rb", "test/test_completion.rb", "test/test_default_commands.rb", "test/test_default_commands/
|
18
|
+
s.test_files = ["test/helper.rb", "test/test_cli.rb", "test/test_code.rb", "test/test_command.rb", "test/test_command_helpers.rb", "test/test_command_integration.rb", "test/test_command_set.rb", "test/test_completion.rb", "test/test_default_commands/test_context.rb", "test/test_default_commands/test_documentation.rb", "test/test_default_commands/test_gems.rb", "test/test_default_commands/test_help.rb", "test/test_default_commands/test_input.rb", "test/test_default_commands/test_introspection.rb", "test/test_default_commands/test_ls.rb", "test/test_default_commands/test_shell.rb", "test/test_exception_whitelist.rb", "test/test_history_array.rb", "test/test_hooks.rb", "test/test_indent.rb", "test/test_input_stack.rb", "test/test_method.rb", "test/test_pry.rb", "test/test_pry_defaults.rb", "test/test_pry_history.rb", "test/test_pry_output.rb", "test/test_special_locals.rb", "test/test_syntax_checking.rb", "test/test_wrapped_module.rb", "test/testrc", "test/testrcbad"]
|
19
19
|
|
20
20
|
if s.respond_to? :specification_version then
|
21
21
|
s.specification_version = 3
|
@@ -23,14 +23,14 @@ Gem::Specification.new do |s|
|
|
23
23
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
24
24
|
s.add_runtime_dependency(%q<coderay>, ["~> 1.0.5"])
|
25
25
|
s.add_runtime_dependency(%q<slop>, ["< 3", ">= 2.4.4"])
|
26
|
-
s.add_runtime_dependency(%q<method_source>, ["~> 0.7"])
|
26
|
+
s.add_runtime_dependency(%q<method_source>, ["~> 0.7.1"])
|
27
27
|
s.add_development_dependency(%q<bacon>, ["~> 1.1"])
|
28
28
|
s.add_development_dependency(%q<open4>, ["~> 1.3"])
|
29
29
|
s.add_development_dependency(%q<rake>, ["~> 0.9"])
|
30
30
|
else
|
31
31
|
s.add_dependency(%q<coderay>, ["~> 1.0.5"])
|
32
32
|
s.add_dependency(%q<slop>, ["< 3", ">= 2.4.4"])
|
33
|
-
s.add_dependency(%q<method_source>, ["~> 0.7"])
|
33
|
+
s.add_dependency(%q<method_source>, ["~> 0.7.1"])
|
34
34
|
s.add_dependency(%q<bacon>, ["~> 1.1"])
|
35
35
|
s.add_dependency(%q<open4>, ["~> 1.3"])
|
36
36
|
s.add_dependency(%q<rake>, ["~> 0.9"])
|
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
|
|
38
38
|
else
|
39
39
|
s.add_dependency(%q<coderay>, ["~> 1.0.5"])
|
40
40
|
s.add_dependency(%q<slop>, ["< 3", ">= 2.4.4"])
|
41
|
-
s.add_dependency(%q<method_source>, ["~> 0.7"])
|
41
|
+
s.add_dependency(%q<method_source>, ["~> 0.7.1"])
|
42
42
|
s.add_dependency(%q<bacon>, ["~> 1.1"])
|
43
43
|
s.add_dependency(%q<open4>, ["~> 1.3"])
|
44
44
|
s.add_dependency(%q<rake>, ["~> 0.9"])
|
data/test/helper.rb
CHANGED
@@ -16,6 +16,14 @@ $VERBOSE = nil
|
|
16
16
|
# Ensure we do not execute any rc files
|
17
17
|
Pry::RC_FILES.clear
|
18
18
|
|
19
|
+
# inject a variable into a binding
|
20
|
+
def inject_var(name, value, b)
|
21
|
+
Thread.current[:__pry_local__] = value
|
22
|
+
b.eval("#{name} = Thread.current[:__pry_local__]")
|
23
|
+
ensure
|
24
|
+
Thread.current[:__pry_local__] = nil
|
25
|
+
end
|
26
|
+
|
19
27
|
# in case the tests call reset_defaults, ensure we reset them to
|
20
28
|
# amended (test friendly) values
|
21
29
|
class << Pry
|
data/test/test_command.rb
CHANGED
@@ -4,6 +4,7 @@ describe "Pry::Command" do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
@set = Pry::CommandSet.new
|
7
|
+
@set.import Pry::DefaultCommands::Help
|
7
8
|
end
|
8
9
|
|
9
10
|
describe 'call_safely' do
|
@@ -339,5 +340,258 @@ describe "Pry::Command" do
|
|
339
340
|
cmd.new.process_line %(grumpos)
|
340
341
|
}.should.raise(Pry::CommandError)
|
341
342
|
end
|
342
|
-
|
343
|
-
|
343
|
+
end
|
344
|
+
|
345
|
+
describe "block parameters" do
|
346
|
+
before do
|
347
|
+
@context = Object.new
|
348
|
+
@set.command "walking-spanish", "down the hall", :takes_block => true do
|
349
|
+
inject_var(:@x, command_block.call, target)
|
350
|
+
end
|
351
|
+
@set.import Pry::Commands
|
352
|
+
end
|
353
|
+
|
354
|
+
it 'should accept multiline blocks' do
|
355
|
+
redirect_pry_io(InputTester.new("walking-spanish | do",
|
356
|
+
" :jesus",
|
357
|
+
"end",
|
358
|
+
"exit-all"), out = StringIO.new) do
|
359
|
+
Pry.start @context, :commands => @set
|
360
|
+
end
|
361
|
+
@context.instance_variable_get(:@x).should == :jesus
|
362
|
+
end
|
363
|
+
|
364
|
+
it 'should accept normal parameters along with block' do
|
365
|
+
@set.block_command "walking-spanish", "litella's been screeching for a blind pig.", :takes_block => true do |x, y|
|
366
|
+
inject_var(:@x, x, target)
|
367
|
+
inject_var(:@y, y, target)
|
368
|
+
inject_var(:@block_var, command_block.call, target)
|
369
|
+
end
|
370
|
+
redirect_pry_io(InputTester.new("walking-spanish john carl| { :jesus }",
|
371
|
+
"exit-all")) do
|
372
|
+
Pry.start @context, :commands => @set
|
373
|
+
end
|
374
|
+
|
375
|
+
@context.instance_variable_get(:@x).should == "john"
|
376
|
+
@context.instance_variable_get(:@y).should == "carl"
|
377
|
+
@context.instance_variable_get(:@block_var).should == :jesus
|
378
|
+
end
|
379
|
+
|
380
|
+
describe "single line blocks" do
|
381
|
+
it 'should accept blocks with do ; end' do
|
382
|
+
redirect_pry_io(InputTester.new("walking-spanish | do ; :jesus; end",
|
383
|
+
"exit-all"), out = StringIO.new) do
|
384
|
+
Pry.start @context, :commands => @set
|
385
|
+
end
|
386
|
+
@context.instance_variable_get(:@x).should == :jesus
|
387
|
+
end
|
388
|
+
|
389
|
+
it 'should accept blocks with do; end' do
|
390
|
+
redirect_pry_io(InputTester.new("walking-spanish | do; :jesus; end",
|
391
|
+
"exit-all"), out = StringIO.new) do
|
392
|
+
Pry.start @context, :commands => @set
|
393
|
+
end
|
394
|
+
@context.instance_variable_get(:@x).should == :jesus
|
395
|
+
end
|
396
|
+
|
397
|
+
it 'should accept blocks with { }' do
|
398
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
399
|
+
"exit-all"), out = StringIO.new) do
|
400
|
+
Pry.start @context, :commands => @set
|
401
|
+
end
|
402
|
+
@context.instance_variable_get(:@x).should == :jesus
|
403
|
+
end
|
404
|
+
|
405
|
+
end
|
406
|
+
|
407
|
+
describe "block-related content removed from arguments" do
|
408
|
+
|
409
|
+
describe "arg_string" do
|
410
|
+
it 'should remove block-related content from arg_string (with one normal arg)' do
|
411
|
+
@set.block_command "walking-spanish", "down the hall", :takes_block => true do |x, y|
|
412
|
+
inject_var(:@arg_string, arg_string, target)
|
413
|
+
inject_var(:@x, x, target)
|
414
|
+
end
|
415
|
+
redirect_pry_io(InputTester.new("walking-spanish john| { :jesus }",
|
416
|
+
"exit-all")) do
|
417
|
+
Pry.start @context, :commands => @set
|
418
|
+
end
|
419
|
+
@context.instance_variable_get(:@arg_string).should == @context.instance_variable_get(:@x)
|
420
|
+
end
|
421
|
+
|
422
|
+
it 'should remove block-related content from arg_string (with no normal args)' do
|
423
|
+
@set.block_command "walking-spanish", "down the hall", :takes_block => true do
|
424
|
+
inject_var(:@arg_string, arg_string, target)
|
425
|
+
end
|
426
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
427
|
+
"exit-all")) do
|
428
|
+
Pry.start @context, :commands => @set
|
429
|
+
end
|
430
|
+
@context.instance_variable_get(:@arg_string).should == ""
|
431
|
+
end
|
432
|
+
|
433
|
+
it 'should NOT remove block-related content from arg_string when :takes_block => false' do
|
434
|
+
block_string = "| { :jesus }"
|
435
|
+
@set.block_command "walking-spanish", "homemade special", :takes_block => false do
|
436
|
+
inject_var(:@arg_string, arg_string, target)
|
437
|
+
end
|
438
|
+
redirect_pry_io(InputTester.new("walking-spanish #{block_string}",
|
439
|
+
"exit-all")) do
|
440
|
+
Pry.start @context, :commands => @set
|
441
|
+
end
|
442
|
+
@context.instance_variable_get(:@arg_string).should == block_string
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
describe "args" do
|
447
|
+
describe "block_command" do
|
448
|
+
it "should remove block-related content from arguments" do
|
449
|
+
@set.block_command "walking-spanish", "glass is full of sand", :takes_block => true do |x, y|
|
450
|
+
inject_var(:@x, x, target)
|
451
|
+
inject_var(:@y, y, target)
|
452
|
+
end
|
453
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
454
|
+
"exit-all"), out = StringIO.new) do
|
455
|
+
Pry.start @context, :commands => @set
|
456
|
+
end
|
457
|
+
@context.instance_variable_get(:@x).should == nil
|
458
|
+
@context.instance_variable_get(:@y).should == nil
|
459
|
+
end
|
460
|
+
|
461
|
+
it "should NOT remove block-related content from arguments if :takes_block => false" do
|
462
|
+
@set.block_command "walking-spanish", "litella screeching for a blind pig", :takes_block => false do |x, y|
|
463
|
+
inject_var(:@x, x, target)
|
464
|
+
inject_var(:@y, y, target)
|
465
|
+
end
|
466
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
467
|
+
"exit-all"), out = StringIO.new) do
|
468
|
+
Pry.start @context, :commands => @set
|
469
|
+
end
|
470
|
+
@context.instance_variable_get(:@x).should == "|"
|
471
|
+
@context.instance_variable_get(:@y).should == "{"
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
describe "create_command" do
|
476
|
+
it "should remove block-related content from arguments" do
|
477
|
+
@set.create_command "walking-spanish", "punk sanders carved one out of wood", :takes_block => true do
|
478
|
+
def process(x, y)
|
479
|
+
inject_var(:@x, x, target)
|
480
|
+
inject_var(:@y, y, target)
|
481
|
+
end
|
482
|
+
end
|
483
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
484
|
+
"exit-all"), out = StringIO.new) do
|
485
|
+
Pry.start @context, :commands => @set
|
486
|
+
end
|
487
|
+
@context.instance_variable_get(:@x).should == nil
|
488
|
+
@context.instance_variable_get(:@y).should == nil
|
489
|
+
end
|
490
|
+
|
491
|
+
it "should NOT remove block-related content from arguments if :takes_block => false" do
|
492
|
+
@set.create_command "walking-spanish", "down the hall", :takes_block => false do
|
493
|
+
def process(x, y)
|
494
|
+
inject_var(:@x, x, target)
|
495
|
+
inject_var(:@y, y, target)
|
496
|
+
end
|
497
|
+
end
|
498
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
499
|
+
"exit-all")) do
|
500
|
+
Pry.start @context, :commands => @set
|
501
|
+
end
|
502
|
+
@context.instance_variable_get(:@x).should == "|"
|
503
|
+
@context.instance_variable_get(:@y).should == "{"
|
504
|
+
end
|
505
|
+
end
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
describe "blocks can take parameters" do
|
510
|
+
describe "{} style blocks" do
|
511
|
+
it 'should accept multiple parameters' do
|
512
|
+
@set.block_command "walking-spanish", "down the hall", :takes_block => true do
|
513
|
+
inject_var(:@x, command_block.call(1, 2), target)
|
514
|
+
end
|
515
|
+
|
516
|
+
redirect_pry_io(InputTester.new("walking-spanish | { |x, y| [x, y] }",
|
517
|
+
"exit-all")) do
|
518
|
+
Pry.start @context, :commands => @set
|
519
|
+
end
|
520
|
+
@context.instance_variable_get(:@x).should == [1, 2]
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
describe "do/end style blocks" do
|
525
|
+
it 'should accept multiple parameters' do
|
526
|
+
@set.create_command "walking-spanish", "litella", :takes_block => true do
|
527
|
+
def process
|
528
|
+
inject_var(:@x, command_block.call(1, 2), target)
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
redirect_pry_io(InputTester.new("walking-spanish | do |x, y|",
|
533
|
+
" [x, y]",
|
534
|
+
"end",
|
535
|
+
"exit-all")) do
|
536
|
+
Pry.start @context, :commands => @set
|
537
|
+
end
|
538
|
+
@context.instance_variable_get(:@x).should == [1, 2]
|
539
|
+
end
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
describe "closure behaviour" do
|
544
|
+
it 'should close over locals in the definition context' do
|
545
|
+
redirect_pry_io(InputTester.new("var = :hello",
|
546
|
+
"walking-spanish | { var }",
|
547
|
+
"exit-all")) do
|
548
|
+
Pry.start @context, :commands => @set
|
549
|
+
end
|
550
|
+
@context.instance_variable_get(:@x).should == :hello
|
551
|
+
end
|
552
|
+
end
|
553
|
+
|
554
|
+
describe "exposing block parameter" do
|
555
|
+
describe "block_command" do
|
556
|
+
it "should expose block in command_block method" do
|
557
|
+
@set.block_command "walking-spanish", "glass full of sand", :takes_block => true do
|
558
|
+
inject_var(:@x, command_block.call, target)
|
559
|
+
end
|
560
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
561
|
+
"exit-all")) do
|
562
|
+
Pry.start @context, :commands => @set
|
563
|
+
end
|
564
|
+
@context.instance_variable_get(:@x).should == :jesus
|
565
|
+
end
|
566
|
+
end
|
567
|
+
|
568
|
+
describe "create_command" do
|
569
|
+
it "should NOT expose &block in create_command's process method" do
|
570
|
+
@set.create_command "walking-spanish", "down the hall", :takes_block => true do
|
571
|
+
def process(&block)
|
572
|
+
inject_var(:@x, block.call, target)
|
573
|
+
end
|
574
|
+
end
|
575
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
576
|
+
"exit-all")) do
|
577
|
+
Pry.start @context, :commands => @set
|
578
|
+
end
|
579
|
+
@context.instance_variable_get(:@x).should == nil
|
580
|
+
end
|
581
|
+
|
582
|
+
it "should expose block in command_block method" do
|
583
|
+
@set.create_command "walking-spanish", "homemade special", :takes_block => true do
|
584
|
+
def process
|
585
|
+
inject_var(:@x, command_block.call, target)
|
586
|
+
end
|
587
|
+
end
|
588
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
589
|
+
"exit-all"), out = StringIO.new) do
|
590
|
+
Pry.start @context, :commands => @set
|
591
|
+
end
|
592
|
+
@context.instance_variable_get(:@x).should == :jesus
|
593
|
+
end
|
594
|
+
end
|
595
|
+
end
|
596
|
+
end
|
597
|
+
end
|