pry 0.9.12.2 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1141 -0
  3. data/LICENSE +2 -2
  4. data/README.md +466 -0
  5. data/bin/pry +4 -7
  6. data/lib/pry/basic_object.rb +10 -0
  7. data/lib/pry/block_command.rb +22 -0
  8. data/lib/pry/class_command.rb +194 -0
  9. data/lib/pry/cli.rb +97 -92
  10. data/lib/pry/code/code_file.rb +114 -0
  11. data/lib/pry/code/code_range.rb +7 -4
  12. data/lib/pry/code/loc.rb +27 -14
  13. data/lib/pry/code.rb +62 -90
  14. data/lib/pry/code_object.rb +83 -39
  15. data/lib/pry/color_printer.rb +66 -0
  16. data/lib/pry/command.rb +202 -371
  17. data/lib/pry/command_set.rb +151 -133
  18. data/lib/pry/command_state.rb +31 -0
  19. data/lib/pry/commands/amend_line.rb +86 -82
  20. data/lib/pry/commands/bang.rb +18 -14
  21. data/lib/pry/commands/bang_pry.rb +15 -11
  22. data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
  23. data/lib/pry/commands/cat/exception_formatter.rb +85 -73
  24. data/lib/pry/commands/cat/file_formatter.rb +56 -63
  25. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  26. data/lib/pry/commands/cat.rb +64 -47
  27. data/lib/pry/commands/cd.rb +42 -26
  28. data/lib/pry/commands/change_inspector.rb +34 -0
  29. data/lib/pry/commands/change_prompt.rb +51 -0
  30. data/lib/pry/commands/clear_screen.rb +20 -0
  31. data/lib/pry/commands/code_collector.rb +148 -131
  32. data/lib/pry/commands/disable_pry.rb +23 -19
  33. data/lib/pry/commands/easter_eggs.rb +23 -34
  34. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  35. data/lib/pry/commands/edit/file_and_line_locator.rb +33 -24
  36. data/lib/pry/commands/edit.rb +183 -167
  37. data/lib/pry/commands/exit.rb +40 -35
  38. data/lib/pry/commands/exit_all.rb +24 -20
  39. data/lib/pry/commands/exit_program.rb +20 -17
  40. data/lib/pry/commands/find_method.rb +167 -167
  41. data/lib/pry/commands/fix_indent.rb +16 -12
  42. data/lib/pry/commands/help.rb +140 -133
  43. data/lib/pry/commands/hist.rb +153 -132
  44. data/lib/pry/commands/import_set.rb +20 -15
  45. data/lib/pry/commands/jump_to.rb +25 -21
  46. data/lib/pry/commands/list_inspectors.rb +42 -0
  47. data/lib/pry/commands/ls/constants.rb +75 -0
  48. data/lib/pry/commands/ls/formatter.rb +55 -0
  49. data/lib/pry/commands/ls/globals.rb +50 -0
  50. data/lib/pry/commands/ls/grep.rb +23 -0
  51. data/lib/pry/commands/ls/instance_vars.rb +40 -0
  52. data/lib/pry/commands/ls/interrogatable.rb +24 -0
  53. data/lib/pry/commands/ls/jruby_hacks.rb +55 -0
  54. data/lib/pry/commands/ls/local_names.rb +37 -0
  55. data/lib/pry/commands/ls/local_vars.rb +47 -0
  56. data/lib/pry/commands/ls/ls_entity.rb +65 -0
  57. data/lib/pry/commands/ls/methods.rb +55 -0
  58. data/lib/pry/commands/ls/methods_helper.rb +50 -0
  59. data/lib/pry/commands/ls/self_methods.rb +34 -0
  60. data/lib/pry/commands/ls.rb +100 -303
  61. data/lib/pry/commands/nesting.rb +21 -17
  62. data/lib/pry/commands/play.rb +93 -49
  63. data/lib/pry/commands/pry_backtrace.rb +22 -18
  64. data/lib/pry/commands/pry_version.rb +15 -11
  65. data/lib/pry/commands/raise_up.rb +33 -27
  66. data/lib/pry/commands/reload_code.rb +57 -48
  67. data/lib/pry/commands/reset.rb +16 -12
  68. data/lib/pry/commands/ri.rb +57 -38
  69. data/lib/pry/commands/save_file.rb +45 -43
  70. data/lib/pry/commands/shell_command.rb +66 -34
  71. data/lib/pry/commands/shell_mode.rb +22 -20
  72. data/lib/pry/commands/show_doc.rb +80 -65
  73. data/lib/pry/commands/show_info.rb +193 -159
  74. data/lib/pry/commands/show_input.rb +16 -11
  75. data/lib/pry/commands/show_source.rb +113 -33
  76. data/lib/pry/commands/stat.rb +35 -31
  77. data/lib/pry/commands/switch_to.rb +21 -15
  78. data/lib/pry/commands/toggle_color.rb +21 -13
  79. data/lib/pry/commands/watch_expression/expression.rb +43 -0
  80. data/lib/pry/commands/watch_expression.rb +110 -0
  81. data/lib/pry/commands/whereami.rb +157 -134
  82. data/lib/pry/commands/wtf.rb +78 -40
  83. data/lib/pry/config/attributable.rb +22 -0
  84. data/lib/pry/config/lazy_value.rb +29 -0
  85. data/lib/pry/config/memoized_value.rb +34 -0
  86. data/lib/pry/config/value.rb +24 -0
  87. data/lib/pry/config.rb +290 -220
  88. data/lib/pry/control_d_handler.rb +28 -0
  89. data/lib/pry/core_extensions.rb +50 -27
  90. data/lib/pry/editor.rb +130 -102
  91. data/lib/pry/env.rb +18 -0
  92. data/lib/pry/exception_handler.rb +43 -0
  93. data/lib/pry/exceptions.rb +73 -0
  94. data/lib/pry/forwardable.rb +27 -0
  95. data/lib/pry/helpers/base_helpers.rb +22 -151
  96. data/lib/pry/helpers/command_helpers.rb +55 -63
  97. data/lib/pry/helpers/documentation_helpers.rb +21 -13
  98. data/lib/pry/helpers/options_helpers.rb +15 -8
  99. data/lib/pry/helpers/platform.rb +55 -0
  100. data/lib/pry/helpers/table.rb +44 -32
  101. data/lib/pry/helpers/text.rb +96 -86
  102. data/lib/pry/helpers.rb +3 -0
  103. data/lib/pry/history.rb +101 -70
  104. data/lib/pry/hooks.rb +67 -137
  105. data/lib/pry/indent.rb +79 -73
  106. data/lib/pry/input_completer.rb +283 -0
  107. data/lib/pry/input_lock.rb +129 -0
  108. data/lib/pry/inspector.rb +39 -0
  109. data/lib/pry/last_exception.rb +61 -0
  110. data/lib/pry/method/disowned.rb +19 -5
  111. data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +51 -42
  112. data/lib/pry/method/weird_method_locator.rb +80 -44
  113. data/lib/pry/method.rb +225 -176
  114. data/lib/pry/object_path.rb +91 -0
  115. data/lib/pry/output.rb +136 -0
  116. data/lib/pry/pager.rb +227 -68
  117. data/lib/pry/prompt.rb +214 -0
  118. data/lib/pry/pry_class.rb +216 -289
  119. data/lib/pry/pry_instance.rb +438 -500
  120. data/lib/pry/repl.rb +256 -0
  121. data/lib/pry/repl_file_loader.rb +34 -35
  122. data/lib/pry/ring.rb +89 -0
  123. data/lib/pry/slop/LICENSE +20 -0
  124. data/lib/pry/slop/commands.rb +190 -0
  125. data/lib/pry/slop/option.rb +210 -0
  126. data/lib/pry/slop.rb +672 -0
  127. data/lib/pry/syntax_highlighter.rb +26 -0
  128. data/lib/pry/system_command_handler.rb +17 -0
  129. data/lib/pry/testable/evalable.rb +24 -0
  130. data/lib/pry/testable/mockable.rb +22 -0
  131. data/lib/pry/testable/pry_tester.rb +88 -0
  132. data/lib/pry/testable/utility.rb +34 -0
  133. data/lib/pry/testable/variables.rb +52 -0
  134. data/lib/pry/testable.rb +68 -0
  135. data/lib/pry/version.rb +3 -1
  136. data/lib/pry/warning.rb +20 -0
  137. data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +36 -43
  138. data/lib/pry/wrapped_module.rb +102 -103
  139. data/lib/pry.rb +135 -261
  140. metadata +94 -283
  141. data/.document +0 -2
  142. data/.gitignore +0 -16
  143. data/.travis.yml +0 -21
  144. data/.yardopts +0 -1
  145. data/CHANGELOG +0 -534
  146. data/CONTRIBUTORS +0 -55
  147. data/Gemfile +0 -9
  148. data/Guardfile +0 -62
  149. data/README.markdown +0 -400
  150. data/Rakefile +0 -140
  151. data/TODO +0 -117
  152. data/lib/pry/commands/disabled_commands.rb +0 -2
  153. data/lib/pry/commands/gem_cd.rb +0 -26
  154. data/lib/pry/commands/gem_install.rb +0 -29
  155. data/lib/pry/commands/gem_list.rb +0 -33
  156. data/lib/pry/commands/gem_open.rb +0 -29
  157. data/lib/pry/commands/gist.rb +0 -102
  158. data/lib/pry/commands/install_command.rb +0 -51
  159. data/lib/pry/commands/simple_prompt.rb +0 -22
  160. data/lib/pry/commands.rb +0 -6
  161. data/lib/pry/completion.rb +0 -304
  162. data/lib/pry/custom_completions.rb +0 -6
  163. data/lib/pry/history_array.rb +0 -116
  164. data/lib/pry/plugins.rb +0 -103
  165. data/lib/pry/rbx_method.rb +0 -13
  166. data/lib/pry/rbx_path.rb +0 -22
  167. data/lib/pry/rubygem.rb +0 -74
  168. data/lib/pry/terminal.rb +0 -78
  169. data/lib/pry/test/helper.rb +0 -185
  170. data/man/pry.1 +0 -195
  171. data/man/pry.1.html +0 -204
  172. data/man/pry.1.ronn +0 -141
  173. data/pry.gemspec +0 -30
  174. data/spec/Procfile +0 -3
  175. data/spec/cli_spec.rb +0 -78
  176. data/spec/code_object_spec.rb +0 -277
  177. data/spec/code_spec.rb +0 -219
  178. data/spec/command_helpers_spec.rb +0 -29
  179. data/spec/command_integration_spec.rb +0 -644
  180. data/spec/command_set_spec.rb +0 -627
  181. data/spec/command_spec.rb +0 -821
  182. data/spec/commands/amend_line_spec.rb +0 -247
  183. data/spec/commands/bang_spec.rb +0 -19
  184. data/spec/commands/cat_spec.rb +0 -164
  185. data/spec/commands/cd_spec.rb +0 -250
  186. data/spec/commands/disable_pry_spec.rb +0 -25
  187. data/spec/commands/edit_spec.rb +0 -727
  188. data/spec/commands/exit_all_spec.rb +0 -34
  189. data/spec/commands/exit_program_spec.rb +0 -19
  190. data/spec/commands/exit_spec.rb +0 -34
  191. data/spec/commands/find_method_spec.rb +0 -70
  192. data/spec/commands/gem_list_spec.rb +0 -26
  193. data/spec/commands/gist_spec.rb +0 -79
  194. data/spec/commands/help_spec.rb +0 -56
  195. data/spec/commands/hist_spec.rb +0 -181
  196. data/spec/commands/jump_to_spec.rb +0 -15
  197. data/spec/commands/ls_spec.rb +0 -181
  198. data/spec/commands/play_spec.rb +0 -140
  199. data/spec/commands/raise_up_spec.rb +0 -56
  200. data/spec/commands/save_file_spec.rb +0 -177
  201. data/spec/commands/show_doc_spec.rb +0 -510
  202. data/spec/commands/show_input_spec.rb +0 -17
  203. data/spec/commands/show_source_spec.rb +0 -782
  204. data/spec/commands/whereami_spec.rb +0 -203
  205. data/spec/completion_spec.rb +0 -239
  206. data/spec/control_d_handler_spec.rb +0 -58
  207. data/spec/documentation_helper_spec.rb +0 -73
  208. data/spec/editor_spec.rb +0 -79
  209. data/spec/exception_whitelist_spec.rb +0 -21
  210. data/spec/fixtures/candidate_helper1.rb +0 -11
  211. data/spec/fixtures/candidate_helper2.rb +0 -8
  212. data/spec/fixtures/example.erb +0 -5
  213. data/spec/fixtures/example_nesting.rb +0 -33
  214. data/spec/fixtures/show_source_doc_examples.rb +0 -15
  215. data/spec/fixtures/testrc +0 -2
  216. data/spec/fixtures/testrcbad +0 -2
  217. data/spec/fixtures/whereami_helper.rb +0 -6
  218. data/spec/helper.rb +0 -34
  219. data/spec/helpers/bacon.rb +0 -86
  220. data/spec/helpers/mock_pry.rb +0 -43
  221. data/spec/helpers/table_spec.rb +0 -105
  222. data/spec/history_array_spec.rb +0 -67
  223. data/spec/hooks_spec.rb +0 -522
  224. data/spec/indent_spec.rb +0 -301
  225. data/spec/input_stack_spec.rb +0 -90
  226. data/spec/method_spec.rb +0 -482
  227. data/spec/prompt_spec.rb +0 -60
  228. data/spec/pry_defaults_spec.rb +0 -419
  229. data/spec/pry_history_spec.rb +0 -99
  230. data/spec/pry_output_spec.rb +0 -95
  231. data/spec/pry_spec.rb +0 -504
  232. data/spec/run_command_spec.rb +0 -25
  233. data/spec/sticky_locals_spec.rb +0 -157
  234. data/spec/syntax_checking_spec.rb +0 -81
  235. data/spec/wrapped_module_spec.rb +0 -261
  236. data/wiki/Customizing-pry.md +0 -397
  237. data/wiki/Home.md +0 -4
@@ -1,29 +0,0 @@
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 and refreshes the gem cache so that you can immediately
12
- 'require GEM_FILE'.
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
- end
26
- end
27
-
28
- Pry::Commands.add_command(Pry::Command::GemInstall)
29
- end
@@ -1,33 +0,0 @@
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
@@ -1,29 +0,0 @@
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
@@ -1,102 +0,0 @@
1
- class Pry
2
- class Command::Gist < Pry::ClassCommand
3
- match 'gist'
4
- group 'Misc'
5
- description 'Playback a string variable or a method or a file as input.'
6
- command_options :requires_gem => "jist"
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 'jist'
20
- end
21
-
22
- def options(opt)
23
- CodeCollector.inject_options(opt)
24
- opt.on :login, "Authenticate the jist 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 Jist.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
- Jist.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 = Jist.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
- Jist.copy(url)
90
- message << ", which is now in the clipboard."
91
- rescue Jist::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
- Pry::Commands.alias_command 'jist', 'gist'
102
- end
@@ -1,51 +0,0 @@
1
- class Pry
2
- class Command::InstallCommand < Pry::ClassCommand
3
- match 'install-command'
4
- group 'Commands'
5
- description 'Install a disabled command.'
6
-
7
- banner <<-'BANNER'
8
- Usage: install-command COMMAND
9
-
10
- Installs the gems necessary to run the given COMMAND. You will generally not
11
- need to run this unless told to by an error message.
12
- BANNER
13
-
14
- def process(name)
15
- require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller
16
- command = find_command(name)
17
-
18
- if command_dependencies_met?(command.options)
19
- output.puts "Dependencies for #{command.name} are met. Nothing to do."
20
- return
21
- end
22
-
23
- output.puts "Attempting to install `#{name}` command..."
24
- gems_to_install = Array(command.options[:requires_gem])
25
-
26
- gems_to_install.each do |g|
27
- next if Rubygem.installed?(g)
28
- output.puts "Installing `#{g}` gem..."
29
-
30
- begin
31
- Gem::DependencyInstaller.new.install(g)
32
- rescue Gem::GemNotFoundException
33
- raise CommandError, "Required Gem: `#{g}` not found. Aborting command installation."
34
- end
35
- end
36
-
37
- Gem.refresh
38
- gems_to_install.each do |g|
39
- begin
40
- require g
41
- rescue LoadError
42
- raise CommandError, "Required Gem: `#{g}` installed but not found?!. Aborting command installation."
43
- end
44
- end
45
-
46
- output.puts "Installation of `#{name}` successful! Type `help #{name}` for information"
47
- end
48
- end
49
-
50
- Pry::Commands.add_command(Pry::Command::InstallCommand)
51
- end
@@ -1,22 +0,0 @@
1
- class Pry
2
- class Command::SimplePrompt < Pry::ClassCommand
3
- match 'simple-prompt'
4
- group 'Misc'
5
- description 'Toggle the simple prompt.'
6
-
7
- banner <<-'BANNER'
8
- Toggle the simple prompt.
9
- BANNER
10
-
11
- def process
12
- case _pry_.prompt
13
- when Pry::SIMPLE_PROMPT
14
- _pry_.pop_prompt
15
- else
16
- _pry_.push_prompt Pry::SIMPLE_PROMPT
17
- end
18
- end
19
- end
20
-
21
- Pry::Commands.add_command(Pry::Command::SimplePrompt)
22
- end
data/lib/pry/commands.rb DELETED
@@ -1,6 +0,0 @@
1
- # Default commands used by Pry.
2
- Pry::Commands = Pry::CommandSet.new
3
-
4
- Dir[File.expand_path('../commands', __FILE__) + '/*.rb'].each do |file|
5
- require file
6
- end
@@ -1,304 +0,0 @@
1
- # taken from irb
2
-
3
- class Pry
4
-
5
- module BondCompleter
6
-
7
- def self.build_completion_proc(target, pry=nil, commands=[""])
8
- if !@started
9
- @started = true
10
- start
11
- end
12
-
13
- Pry.current[:pry] = pry
14
- proc{ |*a| Bond.agent.call(*a) }
15
- end
16
-
17
- def self.start
18
- Bond.start(:eval_binding => lambda{ Pry.current[:pry].current_context })
19
- Bond.complete(:on => /\A/) do |input|
20
- Pry.commands.complete(input.line,
21
- :pry_instance => Pry.current[:pry],
22
- :target => Pry.current[:pry].current_context,
23
- :command_set => Pry.current[:pry].commands)
24
- end
25
- end
26
-
27
- end
28
-
29
- # Implements tab completion for Readline in Pry
30
- module InputCompleter
31
-
32
- if Readline.respond_to?("basic_word_break_characters=")
33
- Readline.basic_word_break_characters = " \t\n\"\\'`><=;|&{("
34
- end
35
-
36
- Readline.completion_append_character = nil
37
-
38
- ReservedWords = [
39
- "BEGIN", "END",
40
- "alias", "and",
41
- "begin", "break",
42
- "case", "class",
43
- "def", "defined", "do",
44
- "else", "elsif", "end", "ensure",
45
- "false", "for",
46
- "if", "in",
47
- "module",
48
- "next", "nil", "not",
49
- "or",
50
- "redo", "rescue", "retry", "return",
51
- "self", "super",
52
- "then", "true",
53
- "undef", "unless", "until",
54
- "when", "while",
55
- "yield" ]
56
-
57
- Operators = [
58
- "%", "&", "*", "**", "+", "-", "/",
59
- "<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", ">>",
60
- "[]", "[]=", "^", "!", "!=", "!~"
61
- ]
62
-
63
- # Return a new completion proc for use by Readline.
64
- # @param [Binding] target The current binding context.
65
- # @param [Array<String>] commands The array of Pry commands.
66
- def self.build_completion_proc(target, pry=nil, commands=[""])
67
-
68
- proc do |input|
69
-
70
- # if there are multiple contexts e.g. cd 1/2/3
71
- # get new target for 1/2 and find candidates for 3
72
- path, input = build_path(input)
73
-
74
- # We silence warnings here or Ruby 1.8 cries about "multiple values for
75
- # block 0 for 1".
76
- Helpers::BaseHelpers.silence_warnings do
77
- unless path.call.empty?
78
- target = begin
79
- ctx = Helpers::BaseHelpers.context_from_object_path(path.call, pry)
80
- ctx.first
81
- rescue Pry::CommandError
82
- []
83
- end
84
- target = target.last
85
- end
86
- end
87
-
88
- begin
89
- bind = target
90
-
91
- case input
92
-
93
-
94
- # Complete stdlib symbols
95
-
96
- when /^(\/[^\/]*\/)\.([^.]*)$/
97
- # Regexp
98
- receiver = $1
99
- message = Regexp.quote($2)
100
-
101
- candidates = Regexp.instance_methods.collect(&:to_s)
102
- select_message(path, receiver, message, candidates)
103
-
104
- when /^([^\]]*\])\.([^.]*)$/
105
- # Array
106
- receiver = $1
107
- message = Regexp.quote($2)
108
-
109
- candidates = Array.instance_methods.collect(&:to_s)
110
- select_message(path, receiver, message, candidates)
111
-
112
- when /^([^\}]*\})\.([^.]*)$/
113
- # Proc or Hash
114
- receiver = $1
115
- message = Regexp.quote($2)
116
-
117
- candidates = Proc.instance_methods.collect(&:to_s)
118
- candidates |= Hash.instance_methods.collect(&:to_s)
119
- select_message(path, receiver, message, candidates)
120
-
121
- when /^(:[^:.]*)$/
122
- # Symbol
123
- if Symbol.respond_to?(:all_symbols)
124
- sym = Regexp.quote($1)
125
- candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
126
-
127
- candidates.grep(/^#{sym}/)
128
- else
129
- []
130
- end
131
-
132
- when /^::([A-Z][^:\.\(]*)$/
133
- # Absolute Constant or class methods
134
- receiver = $1
135
- candidates = Object.constants.collect(&:to_s)
136
- candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
137
-
138
-
139
- # Complete target symbols
140
-
141
- when /^([A-Z][A-Za-z0-9]*)$/
142
- # Constant
143
- message = $1
144
-
145
- begin
146
- context = target.eval("self")
147
- context = context.class unless context.respond_to? :constants
148
- candidates = context.constants.collect(&:to_s)
149
- rescue
150
- candidates = []
151
- end
152
- candidates = candidates.grep(/^#{message}/).collect(&path)
153
-
154
- when /^([A-Z].*)::([^:.]*)$/
155
- # Constant or class methods
156
- receiver = $1
157
- message = Regexp.quote($2)
158
- begin
159
- candidates = eval("#{receiver}.constants.collect(&:to_s)", bind)
160
- candidates |= eval("#{receiver}.methods.collect(&:to_s)", bind)
161
- rescue RescuableException
162
- candidates = []
163
- end
164
- candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e}
165
-
166
- when /^(:[^:.]+)\.([^.]*)$/
167
- # Symbol
168
- receiver = $1
169
- message = Regexp.quote($2)
170
-
171
- candidates = Symbol.instance_methods.collect(&:to_s)
172
- select_message(path, receiver, message, candidates)
173
-
174
- when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/
175
- # Numeric
176
- receiver = $1
177
- message = Regexp.quote($5)
178
-
179
- begin
180
- candidates = eval(receiver, bind).methods.collect(&:to_s)
181
- rescue RescuableException
182
- candidates = []
183
- end
184
- select_message(path, receiver, message, candidates)
185
-
186
- when /^(-?0x[0-9a-fA-F_]+)\.([^.]*)$/#
187
- # Numeric(0xFFFF)
188
- receiver = $1
189
- message = Regexp.quote($2)
190
-
191
- begin
192
- candidates = eval(receiver, bind).methods.collect(&:to_s)
193
- rescue RescuableException
194
- candidates = []
195
- end
196
- select_message(path, receiver, message, candidates)
197
-
198
- when /^(\$[^.]*)$/
199
- # Global variables
200
- regmessage = Regexp.new(Regexp.quote($1))
201
- candidates = global_variables.collect(&:to_s).grep(regmessage)
202
-
203
- when /^([^."].*)\.([^.]*)$/
204
- # Variable
205
- receiver = $1
206
- message = Regexp.quote($2)
207
-
208
- gv = eval("global_variables", bind).collect(&:to_s)
209
- lv = eval("local_variables", bind).collect(&:to_s)
210
- cv = eval("self.class.constants", bind).collect(&:to_s)
211
-
212
- if (gv | lv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
213
- # foo.func and foo is local var. OR
214
- # Foo::Bar.func
215
- begin
216
- candidates = eval("#{receiver}.methods", bind).collect(&:to_s)
217
- rescue RescuableException
218
- candidates = []
219
- end
220
- else
221
- # func1.func2
222
- candidates = []
223
- ObjectSpace.each_object(Module){|m|
224
- begin
225
- name = m.name.to_s
226
- rescue RescuableException
227
- name = ""
228
- end
229
- next if name != "IRB::Context" and
230
- /^(IRB|SLex|RubyLex|RubyToken)/ =~ name
231
-
232
- # jruby doesn't always provide #instance_methods() on each
233
- # object.
234
- if m.respond_to?(:instance_methods)
235
- candidates.concat m.instance_methods(false).collect(&:to_s)
236
- end
237
- }
238
- candidates.sort!
239
- candidates.uniq!
240
- end
241
- select_message(path, receiver, message, candidates)
242
-
243
- when /^\.([^.]*)$/
244
- # Unknown(maybe String)
245
- receiver = ""
246
- message = Regexp.quote($1)
247
-
248
- candidates = String.instance_methods(true).collect(&:to_s)
249
- select_message(path, receiver, message, candidates)
250
-
251
- else
252
-
253
- candidates = eval(
254
- "methods | private_methods | local_variables | " \
255
- "self.class.constants | instance_variables",
256
- bind
257
- ).collect(&:to_s)
258
-
259
- if eval("respond_to?(:class_variables)", bind)
260
- candidates += eval("class_variables", bind).collect(&:to_s)
261
- end
262
- candidates = (candidates|ReservedWords|commands).grep(/^#{Regexp.quote(input)}/)
263
- candidates.collect(&path)
264
- end
265
- rescue RescuableException
266
- []
267
- end
268
- end
269
- end
270
-
271
- def self.select_message(path, receiver, message, candidates)
272
- candidates.grep(/^#{message}/).collect { |e|
273
- case e
274
- when /^[a-zA-Z_]/
275
- path.call(receiver + "." + e)
276
- when /^[0-9]/
277
- when *Operators
278
- #receiver + " " + e
279
- end
280
- }.compact
281
- end
282
-
283
- # build_path seperates the input into two parts: path and input.
284
- # input is the partial string that should be completed
285
- # path is a proc that takes an input and builds a full path.
286
- def self.build_path(input)
287
-
288
- # check to see if the input is a regex
289
- return proc {|input| input.to_s }, input if input[/\/\./]
290
-
291
- trailing_slash = input.end_with?('/')
292
- contexts = input.chomp('/').split(/\//)
293
- input = contexts[-1]
294
-
295
- path = Proc.new do |input|
296
- p = contexts[0..-2].push(input).join('/')
297
- p += '/' if trailing_slash && !input.nil?
298
- p
299
- end
300
-
301
- return path, input
302
- end
303
- end
304
- end
@@ -1,6 +0,0 @@
1
- class Pry
2
-
3
- # This proc will be instance_eval's against the active Pry instance
4
- DEFAULT_CUSTOM_COMPLETIONS = proc { commands.commands.keys }
5
- FILE_COMPLETIONS = proc { commands.commands.keys + Dir.entries('.') }
6
- end
@@ -1,116 +0,0 @@
1
- class Pry
2
- # A history array is an array to which you can only add elements. Older
3
- # entries are removed progressively, so that the aray never contains more than
4
- # N elements.
5
- #
6
- # History arrays are used by Pry to store the output of the last commands.
7
- #
8
- # @example
9
- # ary = Pry::HistoryArray.new 10
10
- # ary << 1 << 2 << 3
11
- # ary[0] # => 1
12
- # ary[1] # => 2
13
- # 10.times { |n| ary << n }
14
- # ary[0] # => nil
15
- # ary[-1] # => 9
16
- class HistoryArray
17
- include Enumerable
18
-
19
- # @param [Integer] size Maximum amount of objects in the array
20
- def initialize(size)
21
- @max_size = size
22
-
23
- @hash = {}
24
- @count = 0
25
- end
26
-
27
- # Pushes an object at the end of the array
28
- # @param [Object] value Object to be added
29
- def <<(value)
30
- @hash[@count] = value
31
-
32
- if @hash.size > max_size
33
- @hash.delete(@count - max_size)
34
- end
35
-
36
- @count += 1
37
-
38
- self
39
- end
40
-
41
- # @overload [](index)
42
- # @param [Integer] index Index of the item to access.
43
- # @return [Object, nil] Item at that index or nil if it has been removed.
44
- # @overload [](index, size)
45
- # @param [Integer] index Index of the first item to access.
46
- # @param [Integer] size Amount of items to access
47
- # @return [Array, nil] The selected items. Nil if index is greater than
48
- # the size of the array.
49
- # @overload [](range)
50
- # @param [Range<Integer>] range Range of indices to access.
51
- # @return [Array, nil] The selected items. Nil if index is greater than
52
- # the size of the array.
53
- def [](index_or_range, size = nil)
54
- if index_or_range.is_a? Integer
55
- index = convert_index(index_or_range)
56
-
57
- if size
58
- end_index = index + size
59
- index > @count ? nil : (index...[end_index, @count].min).map do |n|
60
- @hash[n]
61
- end
62
- else
63
- @hash[index]
64
- end
65
- else
66
- range = convert_range(index_or_range)
67
- range.begin > @count ? nil : range.map { |n| @hash[n] }
68
- end
69
- end
70
-
71
- # @return [Integer] Amount of objects in the array
72
- def size
73
- @count
74
- end
75
- alias count size
76
- alias length size
77
-
78
- def empty?
79
- size == 0
80
- end
81
-
82
- def each
83
- ((@count - size)...@count).each do |n|
84
- yield @hash[n]
85
- end
86
- end
87
-
88
- def to_a
89
- ((@count - size)...@count).map { |n| @hash[n] }
90
- end
91
-
92
- def pop!
93
- @hash.delete @count - 1
94
- @count -= 1
95
- end
96
-
97
- def inspect
98
- "#<#{self.class} size=#{size} first=#{@count - size} max_size=#{max_size}>"
99
- end
100
-
101
- # @return [Integer] Maximum amount of objects in the array
102
- attr_reader :max_size
103
-
104
- private
105
- def convert_index(n)
106
- n >= 0 ? n : @count + n
107
- end
108
-
109
- def convert_range(range)
110
- end_index = convert_index(range.end)
111
- end_index += 1 unless range.exclude_end?
112
-
113
- Range.new(convert_index(range.begin), [end_index, @count].min, true)
114
- end
115
- end
116
- end