pry 0.10.0.pre2-universal-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +25 -0
  4. data/README.md +406 -0
  5. data/bin/pry +16 -0
  6. data/lib/pry.rb +161 -0
  7. data/lib/pry/cli.rb +220 -0
  8. data/lib/pry/code.rb +346 -0
  9. data/lib/pry/code/code_file.rb +103 -0
  10. data/lib/pry/code/code_range.rb +71 -0
  11. data/lib/pry/code/loc.rb +92 -0
  12. data/lib/pry/code_object.rb +172 -0
  13. data/lib/pry/color_printer.rb +55 -0
  14. data/lib/pry/command.rb +692 -0
  15. data/lib/pry/command_set.rb +443 -0
  16. data/lib/pry/commands.rb +6 -0
  17. data/lib/pry/commands/amend_line.rb +99 -0
  18. data/lib/pry/commands/bang.rb +20 -0
  19. data/lib/pry/commands/bang_pry.rb +17 -0
  20. data/lib/pry/commands/cat.rb +62 -0
  21. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  22. data/lib/pry/commands/cat/exception_formatter.rb +77 -0
  23. data/lib/pry/commands/cat/file_formatter.rb +67 -0
  24. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  25. data/lib/pry/commands/cd.rb +41 -0
  26. data/lib/pry/commands/change_inspector.rb +27 -0
  27. data/lib/pry/commands/change_prompt.rb +26 -0
  28. data/lib/pry/commands/code_collector.rb +165 -0
  29. data/lib/pry/commands/disable_pry.rb +27 -0
  30. data/lib/pry/commands/disabled_commands.rb +2 -0
  31. data/lib/pry/commands/easter_eggs.rb +112 -0
  32. data/lib/pry/commands/edit.rb +195 -0
  33. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  34. data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
  35. data/lib/pry/commands/exit.rb +42 -0
  36. data/lib/pry/commands/exit_all.rb +29 -0
  37. data/lib/pry/commands/exit_program.rb +23 -0
  38. data/lib/pry/commands/find_method.rb +193 -0
  39. data/lib/pry/commands/fix_indent.rb +19 -0
  40. data/lib/pry/commands/gem_cd.rb +26 -0
  41. data/lib/pry/commands/gem_install.rb +32 -0
  42. data/lib/pry/commands/gem_list.rb +33 -0
  43. data/lib/pry/commands/gem_open.rb +29 -0
  44. data/lib/pry/commands/gist.rb +101 -0
  45. data/lib/pry/commands/help.rb +164 -0
  46. data/lib/pry/commands/hist.rb +180 -0
  47. data/lib/pry/commands/import_set.rb +22 -0
  48. data/lib/pry/commands/install_command.rb +53 -0
  49. data/lib/pry/commands/jump_to.rb +29 -0
  50. data/lib/pry/commands/list_inspectors.rb +35 -0
  51. data/lib/pry/commands/list_prompts.rb +35 -0
  52. data/lib/pry/commands/ls.rb +114 -0
  53. data/lib/pry/commands/ls/constants.rb +47 -0
  54. data/lib/pry/commands/ls/formatter.rb +49 -0
  55. data/lib/pry/commands/ls/globals.rb +48 -0
  56. data/lib/pry/commands/ls/grep.rb +21 -0
  57. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  58. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  59. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  60. data/lib/pry/commands/ls/local_names.rb +35 -0
  61. data/lib/pry/commands/ls/local_vars.rb +39 -0
  62. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  63. data/lib/pry/commands/ls/methods.rb +57 -0
  64. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  65. data/lib/pry/commands/ls/self_methods.rb +32 -0
  66. data/lib/pry/commands/nesting.rb +25 -0
  67. data/lib/pry/commands/play.rb +103 -0
  68. data/lib/pry/commands/pry_backtrace.rb +25 -0
  69. data/lib/pry/commands/pry_version.rb +17 -0
  70. data/lib/pry/commands/raise_up.rb +32 -0
  71. data/lib/pry/commands/reload_code.rb +62 -0
  72. data/lib/pry/commands/reset.rb +18 -0
  73. data/lib/pry/commands/ri.rb +60 -0
  74. data/lib/pry/commands/save_file.rb +61 -0
  75. data/lib/pry/commands/shell_command.rb +48 -0
  76. data/lib/pry/commands/shell_mode.rb +25 -0
  77. data/lib/pry/commands/show_doc.rb +83 -0
  78. data/lib/pry/commands/show_info.rb +195 -0
  79. data/lib/pry/commands/show_input.rb +17 -0
  80. data/lib/pry/commands/show_source.rb +50 -0
  81. data/lib/pry/commands/simple_prompt.rb +22 -0
  82. data/lib/pry/commands/stat.rb +40 -0
  83. data/lib/pry/commands/switch_to.rb +23 -0
  84. data/lib/pry/commands/toggle_color.rb +24 -0
  85. data/lib/pry/commands/watch_expression.rb +105 -0
  86. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  87. data/lib/pry/commands/whereami.rb +190 -0
  88. data/lib/pry/commands/wtf.rb +57 -0
  89. data/lib/pry/config.rb +24 -0
  90. data/lib/pry/config/behavior.rb +139 -0
  91. data/lib/pry/config/convenience.rb +26 -0
  92. data/lib/pry/config/default.rb +165 -0
  93. data/lib/pry/core_extensions.rb +131 -0
  94. data/lib/pry/editor.rb +133 -0
  95. data/lib/pry/exceptions.rb +77 -0
  96. data/lib/pry/helpers.rb +5 -0
  97. data/lib/pry/helpers/base_helpers.rb +113 -0
  98. data/lib/pry/helpers/command_helpers.rb +156 -0
  99. data/lib/pry/helpers/documentation_helpers.rb +75 -0
  100. data/lib/pry/helpers/options_helpers.rb +27 -0
  101. data/lib/pry/helpers/table.rb +109 -0
  102. data/lib/pry/helpers/text.rb +107 -0
  103. data/lib/pry/history.rb +125 -0
  104. data/lib/pry/history_array.rb +121 -0
  105. data/lib/pry/hooks.rb +230 -0
  106. data/lib/pry/indent.rb +406 -0
  107. data/lib/pry/input_completer.rb +242 -0
  108. data/lib/pry/input_lock.rb +132 -0
  109. data/lib/pry/inspector.rb +27 -0
  110. data/lib/pry/last_exception.rb +61 -0
  111. data/lib/pry/method.rb +546 -0
  112. data/lib/pry/method/disowned.rb +53 -0
  113. data/lib/pry/method/patcher.rb +125 -0
  114. data/lib/pry/method/weird_method_locator.rb +186 -0
  115. data/lib/pry/module_candidate.rb +136 -0
  116. data/lib/pry/object_path.rb +82 -0
  117. data/lib/pry/output.rb +50 -0
  118. data/lib/pry/pager.rb +234 -0
  119. data/lib/pry/plugins.rb +103 -0
  120. data/lib/pry/prompt.rb +26 -0
  121. data/lib/pry/pry_class.rb +375 -0
  122. data/lib/pry/pry_instance.rb +654 -0
  123. data/lib/pry/rbx_path.rb +22 -0
  124. data/lib/pry/repl.rb +202 -0
  125. data/lib/pry/repl_file_loader.rb +74 -0
  126. data/lib/pry/rubygem.rb +82 -0
  127. data/lib/pry/terminal.rb +79 -0
  128. data/lib/pry/test/helper.rb +170 -0
  129. data/lib/pry/version.rb +3 -0
  130. data/lib/pry/wrapped_module.rb +373 -0
  131. metadata +248 -0
@@ -0,0 +1,29 @@
1
+ class Pry
2
+ class Command::ExitAll < Pry::ClassCommand
3
+ match 'exit-all'
4
+ group 'Navigating Pry'
5
+ description 'End the current Pry session.'
6
+
7
+ banner <<-'BANNER'
8
+ Usage: exit-all [--help]
9
+ Aliases: !!@
10
+
11
+ End the current Pry session (popping all bindings and returning to caller).
12
+ Accepts optional return value.
13
+ BANNER
14
+
15
+ def process
16
+ # calculate user-given value
17
+ exit_value = target.eval(arg_string)
18
+
19
+ # clear the binding stack
20
+ _pry_.binding_stack.clear
21
+
22
+ # break out of the repl loop
23
+ throw(:breakout, exit_value)
24
+ end
25
+ end
26
+
27
+ Pry::Commands.add_command(Pry::Command::ExitAll)
28
+ Pry::Commands.alias_command '!!@', 'exit-all'
29
+ end
@@ -0,0 +1,23 @@
1
+ class Pry
2
+ class Command::ExitProgram < Pry::ClassCommand
3
+ match 'exit-program'
4
+ group 'Navigating Pry'
5
+ description 'End the current program.'
6
+
7
+ banner <<-'BANNER'
8
+ Usage: exit-program [--help]
9
+ Aliases: quit-program
10
+ !!!
11
+
12
+ End the current program.
13
+ BANNER
14
+
15
+ def process
16
+ Kernel.exit target.eval(arg_string).to_i
17
+ end
18
+ end
19
+
20
+ Pry::Commands.add_command(Pry::Command::ExitProgram)
21
+ Pry::Commands.alias_command 'quit-program', 'exit-program'
22
+ Pry::Commands.alias_command '!!!', 'exit-program'
23
+ end
@@ -0,0 +1,193 @@
1
+ class Pry
2
+ class Command::FindMethod < Pry::ClassCommand
3
+ extend Pry::Helpers::BaseHelpers
4
+
5
+ match 'find-method'
6
+ group 'Context'
7
+ description 'Recursively search for a method within a Class/Module or the current namespace.'
8
+ command_options :shellwords => false
9
+
10
+ banner <<-'BANNER'
11
+ Usage: find-method [-n|-c] METHOD [NAMESPACE]
12
+
13
+ Recursively search for a method within a Class/Module or the current namespace.
14
+ Use the `-n` switch (the default) to search for methods whose name matches the
15
+ given regex. Use the `-c` switch to search for methods that contain the given
16
+ code.
17
+
18
+ # Find all methods whose name match /re/ inside
19
+ # the Pry namespace. Matches Pry#repl, etc.
20
+ find-method re Pry
21
+
22
+ # Find all methods that contain the code:
23
+ # output.puts inside the Pry namepsace.
24
+ find-method -c 'output.puts' Pry
25
+ BANNER
26
+
27
+ def options(opt)
28
+ opt.on :n, :name, "Search for a method by name"
29
+ opt.on :c, :content, "Search for a method based on content in Regex form"
30
+ end
31
+
32
+ def process
33
+ return if args.size < 1
34
+ klass = search_class
35
+
36
+ matches = if opts.content?
37
+ content_search(klass)
38
+ else
39
+ name_search(klass)
40
+ end
41
+
42
+ show_search_results(matches)
43
+ end
44
+
45
+ private
46
+
47
+ # @return [Regexp] The pattern to search for.
48
+ def pattern
49
+ @pattern ||= ::Regexp.new args[0]
50
+ end
51
+
52
+ # Output the result of the search.
53
+ #
54
+ # @param [Array] matches
55
+ def show_search_results(matches)
56
+ if matches.empty?
57
+ output.puts text.bold("No Methods Matched")
58
+ else
59
+ print_matches(matches)
60
+ end
61
+ end
62
+
63
+ # The class to search for methods.
64
+ # We only search classes, so if the search object is an
65
+ # instance, return its class. If no search object is given
66
+ # search `target_self`.
67
+ def search_class
68
+ klass = if args[1]
69
+ target.eval(args[1])
70
+ else
71
+ target_self
72
+ end
73
+
74
+ klass.is_a?(Module) ? klass : klass.class
75
+ end
76
+
77
+ # pretty-print a list of matching methods.
78
+ #
79
+ # @param [Array<Method>] matches
80
+ def print_matches(matches)
81
+ grouped = matches.group_by(&:owner)
82
+ order = grouped.keys.sort_by{ |x| x.name || x.to_s }
83
+
84
+ order.each do |klass|
85
+ print_matches_for_class(klass, grouped)
86
+ end
87
+ end
88
+
89
+ # Print matched methods for a class
90
+ def print_matches_for_class(klass, grouped)
91
+ output.puts text.bold(klass.name)
92
+ grouped[klass].each do |method|
93
+ header = method.name_with_owner
94
+ output.puts header + additional_info(header, method)
95
+ end
96
+ end
97
+
98
+ # Return the matched lines of method source if `-c` is given or ""
99
+ # if `-c` was not given
100
+ def additional_info(header, method)
101
+ if opts.content?
102
+ ": " << colorize_code(matched_method_lines(header, method))
103
+ else
104
+ ""
105
+ end
106
+ end
107
+
108
+ def matched_method_lines(header, method)
109
+ method.source.split(/\n/).select {|x| x =~ pattern }.join("\n#{' ' * header.length}")
110
+ end
111
+
112
+ # Run the given block against every constant in the provided namespace.
113
+ #
114
+ # @param [Module] klass The namespace in which to start the search.
115
+ # @param [Hash<Module,Boolean>] done The namespaces we've already visited (private)
116
+ # @yieldparam klass Each class/module in the namespace.
117
+ #
118
+ def recurse_namespace(klass, done={}, &block)
119
+ return if !(Module === klass) || done[klass]
120
+
121
+ done[klass] = true
122
+
123
+ yield klass
124
+
125
+ klass.constants.each do |name|
126
+ next if klass.autoload?(name)
127
+ begin
128
+ const = klass.const_get(name)
129
+ rescue RescuableException
130
+ # constant loading is an inexact science at the best of times,
131
+ # this often happens when a constant was .autoload? but someone
132
+ # tried to load it. It's now not .autoload? but will still raise
133
+ # a NameError when you access it.
134
+ else
135
+ recurse_namespace(const, done, &block)
136
+ end
137
+ end
138
+ end
139
+
140
+ # Gather all the methods in a namespace that pass the given block.
141
+ #
142
+ # @param [Module] namespace The namespace in which to search.
143
+ # @yieldparam [Method] method The method to test
144
+ # @yieldreturn [Boolean]
145
+ # @return [Array<Method>]
146
+ #
147
+ def search_all_methods(namespace)
148
+ done = Hash.new{ |h,k| h[k] = {} }
149
+ matches = []
150
+
151
+ recurse_namespace(namespace) do |klass|
152
+ (Pry::Method.all_from_class(klass) + Pry::Method.all_from_obj(klass)).each do |method|
153
+ next if done[method.owner][method.name]
154
+ done[method.owner][method.name] = true
155
+
156
+ matches << method if yield method
157
+ end
158
+ end
159
+
160
+ matches
161
+ end
162
+
163
+ # Search for all methods with a name that matches the given regex
164
+ # within a namespace.
165
+ #
166
+ # @param [Module] namespace The namespace to search
167
+ # @return [Array<Method>]
168
+ #
169
+ def name_search(namespace)
170
+ search_all_methods(namespace) do |meth|
171
+ meth.name =~ pattern
172
+ end
173
+ end
174
+
175
+ # Search for all methods who's implementation matches the given regex
176
+ # within a namespace.
177
+ #
178
+ # @param [Module] namespace The namespace to search
179
+ # @return [Array<Method>]
180
+ #
181
+ def content_search(namespace)
182
+ search_all_methods(namespace) do |meth|
183
+ begin
184
+ meth.source =~ pattern
185
+ rescue RescuableException
186
+ false
187
+ end
188
+ end
189
+ end
190
+ end
191
+
192
+ Pry::Commands.add_command(Pry::Command::FindMethod)
193
+ end
@@ -0,0 +1,19 @@
1
+ class Pry
2
+ class Command::FixIndent < Pry::ClassCommand
3
+ match 'fix-indent'
4
+ group 'Input and Output'
5
+
6
+ description "Correct the indentation for contents of the input buffer"
7
+
8
+ banner <<-USAGE
9
+ Usage: fix-indent
10
+ USAGE
11
+
12
+ def process
13
+ indented_str = Pry::Indent.indent(eval_string)
14
+ eval_string.replace indented_str
15
+ end
16
+ end
17
+
18
+ Pry::Commands.add_command(Pry::Command::FixIndent)
19
+ end
@@ -0,0 +1,26 @@
1
+ class Pry
2
+ class Command::GemCd < Pry::ClassCommand
3
+ match 'gem-cd'
4
+ group 'Gems'
5
+ description "Change working directory to specified gem's directory."
6
+ command_options :argument_required => true
7
+
8
+ banner <<-'BANNER'
9
+ Usage: gem-cd GEM_NAME
10
+
11
+ Change the current working directory to that in which the given gem is
12
+ installed.
13
+ BANNER
14
+
15
+ def process(gem)
16
+ Dir.chdir(Rubygem.spec(gem).full_gem_path)
17
+ output.puts(Dir.pwd)
18
+ end
19
+
20
+ def complete(str)
21
+ Rubygem.complete(str)
22
+ end
23
+ end
24
+
25
+ Pry::Commands.add_command(Pry::Command::GemCd)
26
+ end
@@ -0,0 +1,32 @@
1
+ class Pry
2
+ class Command::GemInstall < Pry::ClassCommand
3
+ match 'gem-install'
4
+ group 'Gems'
5
+ description 'Install a gem and refresh the gem cache.'
6
+ command_options :argument_required => true
7
+
8
+ banner <<-'BANNER'
9
+ Usage: gem-install GEM_NAME
10
+
11
+ Installs the given gem, refreshes the gem cache, and requires the gem for you
12
+ based on a best guess from the gem name.
13
+
14
+ gem-install pry-stack_explorer
15
+ BANNER
16
+
17
+ def setup
18
+ require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller
19
+ end
20
+
21
+ def process(gem)
22
+ Rubygem.install(gem)
23
+ output.puts "Gem `#{ text.green(gem) }` installed."
24
+ require gem
25
+ rescue LoadError
26
+ require_path = gem.split('-').join('/')
27
+ require require_path
28
+ end
29
+ end
30
+
31
+ Pry::Commands.add_command(Pry::Command::GemInstall)
32
+ end
@@ -0,0 +1,33 @@
1
+ class Pry
2
+ class Command::GemList < Pry::ClassCommand
3
+ match 'gem-list'
4
+ group 'Gems'
5
+ description 'List and search installed gems.'
6
+
7
+ banner <<-'BANNER'
8
+ Usage: gem-list [REGEX]
9
+
10
+ List all installed gems, when a regex is provided, limit the output to those
11
+ that match the regex.
12
+ BANNER
13
+
14
+ def process(pattern = nil)
15
+ pattern = Regexp.compile(pattern || '')
16
+ gems = Rubygem.list(pattern).group_by(&:name)
17
+
18
+ gems.each do |gem, specs|
19
+ specs.sort! do |a,b|
20
+ Gem::Version.new(b.version) <=> Gem::Version.new(a.version)
21
+ end
22
+
23
+ versions = specs.each_with_index.map do |spec, index|
24
+ index == 0 ? text.bright_green(spec.version.to_s) : text.green(spec.version.to_s)
25
+ end
26
+
27
+ output.puts "#{text.default gem} (#{versions.join ', '})"
28
+ end
29
+ end
30
+ end
31
+
32
+ Pry::Commands.add_command(Pry::Command::GemList)
33
+ end
@@ -0,0 +1,29 @@
1
+ class Pry
2
+ class Command::GemOpen < Pry::ClassCommand
3
+ match 'gem-open'
4
+ group 'Gems'
5
+ description 'Opens the working directory of the gem in your editor.'
6
+ command_options :argument_required => true
7
+
8
+ banner <<-'BANNER'
9
+ Usage: gem-open GEM_NAME
10
+
11
+ Change the current working directory to that in which the given gem is
12
+ installed, and then opens your text editor.
13
+
14
+ gem-open pry-exception_explorer
15
+ BANNER
16
+
17
+ def process(gem)
18
+ Dir.chdir(Rubygem.spec(gem).full_gem_path) do
19
+ Pry::Editor.invoke_editor(".", 0, false)
20
+ end
21
+ end
22
+
23
+ def complete(str)
24
+ Rubygem.complete(str)
25
+ end
26
+ end
27
+
28
+ Pry::Commands.add_command(Pry::Command::GemOpen)
29
+ end
@@ -0,0 +1,101 @@
1
+ class Pry
2
+ class Command::Gist < Pry::ClassCommand
3
+ match 'gist'
4
+ group 'Misc'
5
+ description 'Upload code, docs, history to https://gist.github.com/.'
6
+ command_options :requires_gem => "gist"
7
+
8
+ banner <<-'BANNER'
9
+ Usage: gist [OPTIONS] [--help]
10
+
11
+ The gist command enables you to gist code from files and methods to github.
12
+
13
+ gist -i 20 --lines 1..3
14
+ gist Pry#repl --lines 1..-1
15
+ gist Rakefile --lines 5
16
+ BANNER
17
+
18
+ def setup
19
+ require 'gist'
20
+ end
21
+
22
+ def options(opt)
23
+ CodeCollector.inject_options(opt)
24
+ opt.on :login, "Authenticate the gist gem with GitHub"
25
+ opt.on :p, :public, "Create a public gist (default: false)", :default => false
26
+ opt.on :clip, "Copy the selected content to clipboard instead, do NOT gist it", :default => false
27
+ end
28
+
29
+ def process
30
+ return ::Gist.login! if opts.present?(:login)
31
+ cc = CodeCollector.new(args, opts, _pry_)
32
+
33
+ if cc.content =~ /\A\s*\z/
34
+ raise CommandError, "Found no code to gist."
35
+ end
36
+
37
+ if opts.present?(:clip)
38
+ clipboard_content(cc.content)
39
+ else
40
+ # we're overriding the default behavior of the 'in' option (as
41
+ # defined on CodeCollector) with our local behaviour.
42
+ content = opts.present?(:in) ? input_content : cc.content
43
+ gist_content content, cc.file
44
+ end
45
+ end
46
+
47
+ def clipboard_content(content)
48
+ ::Gist.copy(content)
49
+ output.puts "Copied content to clipboard!"
50
+ end
51
+
52
+ def input_content
53
+ content = ""
54
+ CodeCollector.input_expression_ranges.each do |range|
55
+ input_expressions = _pry_.input_array[range] || []
56
+ Array(input_expressions).each_with_index do |code, index|
57
+ corrected_index = index + range.first
58
+ if code && code != ""
59
+ content << code
60
+ if code !~ /;\Z/
61
+ content << "#{comment_expression_result_for_gist(_pry_.config.gist.inspecter.call(_pry_.output_array[corrected_index]))}"
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ content
68
+ end
69
+
70
+ def comment_expression_result_for_gist(result)
71
+ content = ""
72
+ result.lines.each_with_index do |line, index|
73
+ if index == 0
74
+ content << "# => #{line}"
75
+ else
76
+ content << "# #{line}"
77
+ end
78
+ end
79
+
80
+ content
81
+ end
82
+
83
+ def gist_content(content, filename)
84
+ response = ::Gist.gist(content, :filename => filename || "pry_gist.rb", :public => !!opts[:p])
85
+ if response
86
+ url = response['html_url']
87
+ message = "Gist created at URL #{url}"
88
+ begin
89
+ ::Gist.copy(url)
90
+ message << ", which is now in the clipboard."
91
+ rescue ::Gist::ClipboardError
92
+ end
93
+
94
+ output.puts message
95
+ end
96
+ end
97
+ end
98
+
99
+ Pry::Commands.add_command(Pry::Command::Gist)
100
+ Pry::Commands.alias_command 'clipit', 'gist --clip'
101
+ end