pry 0.9.12.6-i386-mingw32 → 0.10.0-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +37 -31
  5. data/lib/pry.rb +38 -151
  6. data/lib/pry/cli.rb +35 -17
  7. data/lib/pry/code.rb +19 -63
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +2 -1
  10. data/lib/pry/code/loc.rb +2 -2
  11. data/lib/pry/code_object.rb +40 -21
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +12 -9
  14. data/lib/pry/command_set.rb +81 -38
  15. data/lib/pry/commands.rb +1 -1
  16. data/lib/pry/commands/amend_line.rb +2 -2
  17. data/lib/pry/commands/bang.rb +1 -1
  18. data/lib/pry/commands/cat.rb +11 -2
  19. data/lib/pry/commands/cat/exception_formatter.rb +6 -7
  20. data/lib/pry/commands/cat/file_formatter.rb +15 -32
  21. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  22. data/lib/pry/commands/cd.rb +14 -3
  23. data/lib/pry/commands/change_inspector.rb +27 -0
  24. data/lib/pry/commands/change_prompt.rb +26 -0
  25. data/lib/pry/commands/code_collector.rb +4 -4
  26. data/lib/pry/commands/easter_eggs.rb +3 -3
  27. data/lib/pry/commands/edit.rb +10 -22
  28. data/lib/pry/commands/edit/exception_patcher.rb +2 -2
  29. data/lib/pry/commands/edit/file_and_line_locator.rb +0 -2
  30. data/lib/pry/commands/exit_program.rb +0 -1
  31. data/lib/pry/commands/find_method.rb +16 -22
  32. data/lib/pry/commands/gem_install.rb +5 -2
  33. data/lib/pry/commands/gem_open.rb +1 -1
  34. data/lib/pry/commands/gist.rb +10 -11
  35. data/lib/pry/commands/help.rb +14 -14
  36. data/lib/pry/commands/hist.rb +27 -8
  37. data/lib/pry/commands/install_command.rb +14 -12
  38. data/lib/pry/commands/list_inspectors.rb +35 -0
  39. data/lib/pry/commands/list_prompts.rb +35 -0
  40. data/lib/pry/commands/ls.rb +72 -296
  41. data/lib/pry/commands/ls/constants.rb +47 -0
  42. data/lib/pry/commands/ls/formatter.rb +49 -0
  43. data/lib/pry/commands/ls/globals.rb +48 -0
  44. data/lib/pry/commands/ls/grep.rb +21 -0
  45. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  46. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  47. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  48. data/lib/pry/commands/ls/local_names.rb +35 -0
  49. data/lib/pry/commands/ls/local_vars.rb +39 -0
  50. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  51. data/lib/pry/commands/ls/methods.rb +57 -0
  52. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  53. data/lib/pry/commands/ls/self_methods.rb +32 -0
  54. data/lib/pry/commands/play.rb +44 -10
  55. data/lib/pry/commands/pry_backtrace.rb +1 -2
  56. data/lib/pry/commands/raise_up.rb +2 -2
  57. data/lib/pry/commands/reload_code.rb +16 -19
  58. data/lib/pry/commands/ri.rb +7 -3
  59. data/lib/pry/commands/shell_command.rb +18 -13
  60. data/lib/pry/commands/shell_mode.rb +2 -4
  61. data/lib/pry/commands/show_doc.rb +5 -0
  62. data/lib/pry/commands/show_info.rb +8 -13
  63. data/lib/pry/commands/show_source.rb +15 -3
  64. data/lib/pry/commands/simple_prompt.rb +1 -1
  65. data/lib/pry/commands/toggle_color.rb +8 -4
  66. data/lib/pry/commands/watch_expression.rb +105 -0
  67. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  68. data/lib/pry/commands/whereami.rb +18 -10
  69. data/lib/pry/commands/wtf.rb +3 -3
  70. data/lib/pry/config.rb +20 -254
  71. data/lib/pry/config/behavior.rb +139 -0
  72. data/lib/pry/config/convenience.rb +26 -0
  73. data/lib/pry/config/default.rb +165 -0
  74. data/lib/pry/core_extensions.rb +31 -21
  75. data/lib/pry/editor.rb +107 -103
  76. data/lib/pry/exceptions.rb +77 -0
  77. data/lib/pry/helpers/base_helpers.rb +22 -109
  78. data/lib/pry/helpers/command_helpers.rb +10 -8
  79. data/lib/pry/helpers/documentation_helpers.rb +1 -2
  80. data/lib/pry/helpers/text.rb +4 -5
  81. data/lib/pry/history.rb +46 -45
  82. data/lib/pry/history_array.rb +6 -1
  83. data/lib/pry/hooks.rb +9 -29
  84. data/lib/pry/indent.rb +6 -6
  85. data/lib/pry/input_completer.rb +242 -0
  86. data/lib/pry/input_lock.rb +132 -0
  87. data/lib/pry/inspector.rb +27 -0
  88. data/lib/pry/last_exception.rb +61 -0
  89. data/lib/pry/method.rb +82 -87
  90. data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +41 -38
  91. data/lib/pry/module_candidate.rb +4 -14
  92. data/lib/pry/object_path.rb +82 -0
  93. data/lib/pry/output.rb +50 -0
  94. data/lib/pry/pager.rb +193 -48
  95. data/lib/pry/plugins.rb +1 -1
  96. data/lib/pry/prompt.rb +26 -0
  97. data/lib/pry/pry_class.rb +149 -230
  98. data/lib/pry/pry_instance.rb +302 -413
  99. data/lib/pry/rbx_path.rb +1 -1
  100. data/lib/pry/repl.rb +202 -0
  101. data/lib/pry/repl_file_loader.rb +20 -26
  102. data/lib/pry/rubygem.rb +13 -5
  103. data/lib/pry/terminal.rb +2 -1
  104. data/lib/pry/test/helper.rb +26 -41
  105. data/lib/pry/version.rb +1 -1
  106. data/lib/pry/wrapped_module.rb +45 -59
  107. metadata +62 -225
  108. data/.document +0 -2
  109. data/.gitignore +0 -16
  110. data/.travis.yml +0 -25
  111. data/.yardopts +0 -1
  112. data/CHANGELOG +0 -534
  113. data/CONTRIBUTORS +0 -55
  114. data/Gemfile +0 -12
  115. data/Rakefile +0 -140
  116. data/TODO +0 -117
  117. data/lib/pry/completion.rb +0 -321
  118. data/lib/pry/custom_completions.rb +0 -6
  119. data/lib/pry/rbx_method.rb +0 -13
  120. data/man/pry.1 +0 -195
  121. data/man/pry.1.html +0 -204
  122. data/man/pry.1.ronn +0 -141
  123. data/pry.gemspec +0 -29
  124. data/spec/Procfile +0 -3
  125. data/spec/cli_spec.rb +0 -78
  126. data/spec/code_object_spec.rb +0 -277
  127. data/spec/code_spec.rb +0 -219
  128. data/spec/command_helpers_spec.rb +0 -29
  129. data/spec/command_integration_spec.rb +0 -644
  130. data/spec/command_set_spec.rb +0 -627
  131. data/spec/command_spec.rb +0 -821
  132. data/spec/commands/amend_line_spec.rb +0 -247
  133. data/spec/commands/bang_spec.rb +0 -19
  134. data/spec/commands/cat_spec.rb +0 -164
  135. data/spec/commands/cd_spec.rb +0 -250
  136. data/spec/commands/disable_pry_spec.rb +0 -25
  137. data/spec/commands/edit_spec.rb +0 -727
  138. data/spec/commands/exit_all_spec.rb +0 -34
  139. data/spec/commands/exit_program_spec.rb +0 -19
  140. data/spec/commands/exit_spec.rb +0 -34
  141. data/spec/commands/find_method_spec.rb +0 -70
  142. data/spec/commands/gem_list_spec.rb +0 -26
  143. data/spec/commands/gist_spec.rb +0 -79
  144. data/spec/commands/help_spec.rb +0 -56
  145. data/spec/commands/hist_spec.rb +0 -181
  146. data/spec/commands/jump_to_spec.rb +0 -15
  147. data/spec/commands/ls_spec.rb +0 -181
  148. data/spec/commands/play_spec.rb +0 -140
  149. data/spec/commands/raise_up_spec.rb +0 -56
  150. data/spec/commands/save_file_spec.rb +0 -177
  151. data/spec/commands/show_doc_spec.rb +0 -510
  152. data/spec/commands/show_input_spec.rb +0 -17
  153. data/spec/commands/show_source_spec.rb +0 -782
  154. data/spec/commands/whereami_spec.rb +0 -203
  155. data/spec/completion_spec.rb +0 -241
  156. data/spec/control_d_handler_spec.rb +0 -58
  157. data/spec/documentation_helper_spec.rb +0 -73
  158. data/spec/editor_spec.rb +0 -79
  159. data/spec/exception_whitelist_spec.rb +0 -21
  160. data/spec/fixtures/candidate_helper1.rb +0 -11
  161. data/spec/fixtures/candidate_helper2.rb +0 -8
  162. data/spec/fixtures/example.erb +0 -5
  163. data/spec/fixtures/example_nesting.rb +0 -33
  164. data/spec/fixtures/show_source_doc_examples.rb +0 -15
  165. data/spec/fixtures/testrc +0 -2
  166. data/spec/fixtures/testrcbad +0 -2
  167. data/spec/fixtures/whereami_helper.rb +0 -6
  168. data/spec/helper.rb +0 -34
  169. data/spec/helpers/bacon.rb +0 -86
  170. data/spec/helpers/mock_pry.rb +0 -43
  171. data/spec/helpers/table_spec.rb +0 -105
  172. data/spec/history_array_spec.rb +0 -67
  173. data/spec/hooks_spec.rb +0 -522
  174. data/spec/indent_spec.rb +0 -301
  175. data/spec/input_stack_spec.rb +0 -90
  176. data/spec/method_spec.rb +0 -482
  177. data/spec/prompt_spec.rb +0 -60
  178. data/spec/pry_defaults_spec.rb +0 -419
  179. data/spec/pry_history_spec.rb +0 -99
  180. data/spec/pry_output_spec.rb +0 -95
  181. data/spec/pry_spec.rb +0 -515
  182. data/spec/run_command_spec.rb +0 -25
  183. data/spec/sticky_locals_spec.rb +0 -157
  184. data/spec/syntax_checking_spec.rb +0 -81
  185. data/spec/wrapped_module_spec.rb +0 -261
  186. data/wiki/Customizing-pry.md +0 -397
  187. data/wiki/Home.md +0 -4
@@ -1,55 +0,0 @@
1
- 1068 John Mair
2
- 372 Conrad Irwin
3
- 215 Ryan Fitzgerald
4
- 108 Kyrylo Silin
5
- 92 Rob Gleeson
6
- 54 Mon ouïe
7
- 51 Lee Jarvis
8
- 47 ☈king
9
- 40 Jordon Bedwell
10
- 28 Yorick Peterse
11
- 18 David Palm
12
- 18 Robert Gleeson
13
- 15 epitron
14
- 12 Andrew Vos
15
- 11 Reginald Tan
16
- 10 Matt Carey
17
- 8 Eero Saynatkari
18
- 8 Trey Lawrence
19
- 6 Jason Laster
20
- 3 misfo
21
- 3 fowlmouth
22
- 3 Darrick Wiebe
23
- 2 Kelsey Judson
24
- 2 Ben Langfeld
25
- 2 Bram Swenson
26
- 2 Erik Michaels-Ober
27
- 2 Ingrid
28
- 2 Vít Ondruch
29
- 2 Xavier Shay
30
- 2 Jonathan Soeder
31
- 2 Eric Christopherson
32
- 2 robgleeson
33
- 1 Ben Pickles
34
- 1 Zeh Rizzatti
35
- 1 shirmung
36
- 1 sonnym
37
- 1 Shawn Anderson
38
- 1 Joe Peduto
39
- 1 Greg Stearns
40
- 1 Jonathan Jackson
41
- 1 Jordan Running
42
- 1 Gosha Arinich
43
- 1 Josh Cheek
44
- 1 Kirill Lashuk
45
- 1 Gerbert Olivé
46
- 1 Larry Gilbert
47
- 1 Lars Haugseth
48
- 1 Loic Nageleisen
49
- 1 Matthew Carey
50
- 1 Michael Bensoussan
51
- 1 Renato Mascarenhas
52
- 1 Havenwood
53
- 1 Sherin C
54
- 1 Sonali Sridhar
55
- 1 Tim Pope
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- group :development do
5
- gem 'jist'
6
- end
7
-
8
- if RbConfig::CONFIG['ruby_install_name'] == 'rbx'
9
- gem 'rubysl-singleton'
10
- gem 'rubysl-prettyprint'
11
- gem 'rb-readline'
12
- end
data/Rakefile DELETED
@@ -1,140 +0,0 @@
1
- require 'rake/clean'
2
- require 'rubygems/package_task'
3
-
4
- $:.unshift 'lib'
5
- require 'pry/version'
6
-
7
- CLOBBER.include('**/*~', '**/*#*', '**/*.log')
8
- CLEAN.include('**/*#*', '**/*#*.*', '**/*_flymake*.*', '**/*_flymake', '**/*.rbc', '**/.#*.*')
9
-
10
- def check_dependencies
11
- require 'bundler'
12
- Bundler.definition.missing_specs
13
-
14
- eval('nil', TOPLEVEL_BINDING, '<main>') # workaround for issue #395
15
- rescue LoadError
16
- # if Bundler isn't installed, we'll just assume your setup is ok.
17
- rescue Bundler::GemNotFound
18
- raise RuntimeError, "You're missing one or more required gems. Run `bundle install` first."
19
- end
20
-
21
- desc "Set up and run tests"
22
- task :default => [:test]
23
-
24
- unless [].respond_to? :shuffle!
25
- class Array
26
- def shuffle!
27
- # TODO: fill this in if anyone cares
28
- self
29
- end
30
- end
31
- end
32
-
33
- def run_specs paths
34
- quiet = ENV['VERBOSE'] ? '' : '-q'
35
- exec "bacon -Ispec -rubygems #{quiet} #{paths.join ' '}"
36
- end
37
-
38
- desc "Run tests"
39
- task :test do
40
- check_dependencies unless ENV['SKIP_DEP_CHECK']
41
- paths =
42
- if explicit_list = ENV['run']
43
- explicit_list.split(',')
44
- else
45
- Dir['spec/**/*_spec.rb'].shuffle!
46
- end
47
- run_specs paths
48
- end
49
- task :spec => :test
50
-
51
- task :recspec do
52
- all = Dir['spec/**/*_spec.rb'].sort_by{|path| File.mtime(path)}.reverse
53
- warn "Running all, sorting by mtime: #{all[0..2].join(' ')} ...etc."
54
- run_specs all
55
- end
56
-
57
- desc "Run pry"
58
- task :pry do
59
- check_dependencies unless ENV['SKIP_DEP_CHECK']
60
- load 'bin/pry'
61
- end
62
-
63
- desc "Show pry version"
64
- task :version do
65
- puts "Pry version: #{Pry::VERSION}"
66
- end
67
-
68
- desc "Profile pry's startup time"
69
- task :profile do
70
- require 'profile'
71
- require 'pry'
72
- Pry.start(TOPLEVEL_BINDING, :input => StringIO.new('exit'))
73
- end
74
-
75
- def modify_base_gemspec
76
- eval(File.read('pry.gemspec')).tap { |s| yield s }
77
- end
78
-
79
- namespace :ruby do
80
- spec = modify_base_gemspec do |s|
81
- s.platform = Gem::Platform::RUBY
82
- end
83
-
84
- Gem::PackageTask.new(spec) do |pkg|
85
- pkg.need_zip = false
86
- pkg.need_tar = false
87
- end
88
- end
89
-
90
- namespace :jruby do
91
- spec = modify_base_gemspec do |s|
92
- s.add_dependency('spoon', '~> 0.0')
93
- s.platform = 'java'
94
- end
95
-
96
- Gem::PackageTask.new(spec) do |pkg|
97
- pkg.need_zip = false
98
- pkg.need_tar = false
99
- end
100
- end
101
-
102
-
103
- [:mingw32, :mswin32].each do |v|
104
- namespace v do
105
- spec = modify_base_gemspec do |s|
106
- s.add_dependency('win32console', '~> 1.3')
107
- s.platform = "i386-#{v}"
108
- end
109
-
110
- Gem::PackageTask.new(spec) do |pkg|
111
- pkg.need_zip = false
112
- pkg.need_tar = false
113
- end
114
- end
115
- end
116
-
117
- desc "build all platform gems at once"
118
- task :gems => [:clean, :rmgems, 'ruby:gem', 'mswin32:gem', 'mingw32:gem', 'jruby:gem']
119
-
120
- desc "remove all platform gems"
121
- task :rmgems => ['ruby:clobber_package']
122
- task :rm_gems => :rmgems
123
- task :rm_pkgs => :rmgems
124
-
125
- desc "reinstall gem"
126
- task :reinstall => :gems do
127
- sh "gem uninstall pry" rescue nil
128
- sh "gem install #{File.dirname(__FILE__)}/pkg/pry-#{Pry::VERSION}.gem"
129
- end
130
-
131
- task :install => :reinstall
132
-
133
- desc "build and push latest gems"
134
- task :pushgems => :gems do
135
- chdir("#{File.dirname(__FILE__)}/pkg") do
136
- Dir["*.gem"].each do |gemfile|
137
- sh "gem push #{gemfile}"
138
- end
139
- end
140
- end
data/TODO DELETED
@@ -1,117 +0,0 @@
1
- 0.9.5
2
- * include method visiblity in show-doc and stat output
3
- * tempfile should end in .rb (for edit -t)
4
- * ls output should not be in array format
5
- * exceptions should allow access to previous items in the backtrace
6
- * input should allow multiple objects which are switched to automatically when EOF is reached on the preceding one
7
- * pry -r should happen in pry
8
- * more plugin-related commands in pry - see installed ones, see activated ones, see available on rubygems
9
- * should also allow plugins be explicitly activated as a command line option
10
- * should not raise if plugin activation fails (should show warning instead)
11
- * more documentation on CommandContext, etc and also command helpers
12
- * fix history saving (should not save all of Readline::HISTORY, but only what changed)
13
- * prevent blank lines going to Readline::HISTORY
14
- * ensure that cat --ex emulates the `whereami` format - includes line numbers and formatted the same, etc
15
- * rename inp and out to _inp_ and _out_ otherwise than can overwrite locals by those names when debugging (not good)
16
- * add source file to stat command
17
- * make plugins use hash instead of array
18
- * ensure edit -t has 'edit' alias (no parameters) and dumps eval_string into buffer
19
- * whitelist exceptions
20
- * hooks system
21
- * jruby shell command support
22
-
23
- 0.9.3
24
- * hist command now excludes last line of input (the command invocation itself)
25
- * hist now has `history` alias
26
- * `pry -r` requires now happen after plugin loading (so as not to interfere with
27
- * new Pry.config.disable_auto_reload option, for turning off auto reloading by edit-method and related
28
- * add better error messages for `cd` command
29
- * add command_prefix
30
- * change some command names to include hyphen, e.g version => pry-version, install => install-command
31
- * do cat --ex and edit --ex
32
- * add reload-method
33
- * fixed exotic object regression - BasicObject.new etc now return "=> unknown"
34
- * converted: import => import-set, version => pry-version, install => install-command
35
- * fix show-doc bug for ruby 1.8 and Kernel.fork
36
- * edit -t (opens a temporary file and evals it in current context when closed)
37
-
38
- 0.9.0
39
- Major features
40
- --------------
41
- * Restructure command system and helpers (almost complete)
42
- * Delete unnecessary commands, add a couple of new ones (e.g amend-line)
43
- * Readline history
44
- * Plugin support
45
- * Support Rubinius core methods
46
- * in[] and out[] arrays
47
- * Improve test coverage (test some commands, etc)
48
-
49
- Minor changes
50
- -------------
51
- * improve edit-method support for various editors
52
- * ensure all commands have appropriate error handing and informative error messages
53
- * show-doc should include signature of method
54
-
55
- Optional
56
- --------
57
- * multi-line readline support
58
-
59
-
60
- 0.8.0
61
- * allow #{} interpolation of all commands
62
- * update documentation! new commands and features and change in behaviour of `run`
63
- * add ; at end of line to suppress return value output
64
- * Remove message spam (before/after hooks)
65
- * stop commands returning a value
66
- * use `redo` in the r() method when encounter a command
67
- * shell functionality should just use system(), but redirect in and
68
- out to Pry.input and Pry.output by reassining $stdin and $stdout
69
- for duration of block.
70
- * basicobject and no to_s/inspect support
71
- * fix documentation, support rdoc and yard properly
72
- * only load Ripper if 1.9 AND MRI (support jruby 1.9, using
73
- RubyParser)
74
- * shell commands invokable file .<command>
75
- * supercharge cat-file so it can syntax highlight sourcecode files
76
-
77
-
78
- 0.7.0
79
- * add pry-doc support with syntax highlighting for docs
80
- * add 'mj' option to ls (restrict to singleton methods)
81
- * add _ex_ local to hold last exception raised in an exception
82
-
83
- 0.6.8
84
- * add whereami command, a la the `ir_b` gem
85
- * make .pryrc be loaded by run-time pry sessions
86
-
87
- 0.6.7
88
- * color support
89
- * --simple-prompt for pry commandline
90
- * -I mode for pry commandline
91
- * --color mode for pry commandline
92
- * clean up requires (put them all in one place)
93
- * simple-prompt command and toggle-color commandd.
94
-
95
- 0.6.1
96
- * !@ command alias for exit_all
97
- * `cd /` for breaking out to pry top level (jump-to 0)
98
- * made `-e` option work in a more effective way for `pry` command line invocation
99
- * exit and exit-all commands now accept a parameter, this parameter becomes the return value of repl()
100
- * `command` method from CommandBase now accepts a :keep_retval arg that determines if command value is returned to pry session or just `nil` (`nil` was old behaviour)
101
- * tests for new :keep_retval and exit-all/exit behaviour; :keep_retval will remain undocumented.
102
-
103
- 0.5.0 release:
104
- * !!!! UPDATE DOCUMENTATION !!!!
105
- * Use clipped version of Pry.view() for large objects
106
- * Exit Pry session on ^d
107
- * Use Shellwords for breaking up parameters to pry commands
108
- * Use OptionParser to parse options for default pry commands
109
- * Add version command
110
- * Refactor 'status' command: add current method info
111
- * Add meth_name_from_binding utility lambda to commands.rb
112
- * Add -M, -m, -v(erbose), -a(ll), -s(uper), -l(ocals), -i(ivars), -k(klass vars) options to ls
113
- * add -i(nstance) option to show-method
114
- * add --help option to most commands
115
- * Get rid of ls_method and ls_imethods (subsumed by more powerful ls)
116
- * Get rid of show_idoc and show_imethod
117
- * Add special eval-file command that evals target file in current context
@@ -1,321 +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
- Pry.require_readline
9
-
10
- # If we're using libedit or bond gem not installed, don't use Bond.
11
- if Readline::VERSION =~ /editline/i || !defined?(Bond)
12
- Pry.config.completer = InputCompleter
13
- return InputCompleter.build_completion_proc(target, pry, commands)
14
- end
15
-
16
- if !@started
17
- @started = true
18
- start
19
- end
20
-
21
- Pry.current[:pry] = pry
22
- proc{ |*a| Bond.agent.call(*a) }
23
- end
24
-
25
- def self.start
26
- Bond.start(:eval_binding => lambda{ Pry.current[:pry].current_context })
27
- Bond.complete(:on => /\A/) do |input|
28
- Pry.commands.complete(input.line,
29
- :pry_instance => Pry.current[:pry],
30
- :target => Pry.current[:pry].current_context,
31
- :command_set => Pry.current[:pry].commands)
32
- end
33
- end
34
-
35
- end
36
-
37
- # Implements tab completion for Readline in Pry
38
- module InputCompleter
39
- ReservedWords = [
40
- "BEGIN", "END",
41
- "alias", "and",
42
- "begin", "break",
43
- "case", "class",
44
- "def", "defined", "do",
45
- "else", "elsif", "end", "ensure",
46
- "false", "for",
47
- "if", "in",
48
- "module",
49
- "next", "nil", "not",
50
- "or",
51
- "redo", "rescue", "retry", "return",
52
- "self", "super",
53
- "then", "true",
54
- "undef", "unless", "until",
55
- "when", "while",
56
- "yield" ]
57
-
58
- Operators = [
59
- "%", "&", "*", "**", "+", "-", "/",
60
- "<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", ">>",
61
- "[]", "[]=", "^", "!", "!=", "!~"
62
- ]
63
-
64
- # If we haven't configured Readline for completion yet, do it now.
65
- # @private
66
- def self.initialize_readline
67
- Pry.require_readline
68
- return if @initialized_readline
69
-
70
- if Readline.respond_to?("basic_word_break_characters=")
71
- Readline.basic_word_break_characters = " \t\n\"\\'`><=;|&{("
72
- end
73
-
74
- Readline.completion_append_character = nil
75
-
76
- @initialized_readline = true
77
- end
78
-
79
- # Return a new completion proc for use by Readline.
80
- # @param [Binding] target The current binding context.
81
- # @param [Array<String>] commands The array of Pry commands.
82
- def self.build_completion_proc(target, pry=nil, commands=[""])
83
- initialize_readline
84
-
85
- proc do |input|
86
-
87
- # if there are multiple contexts e.g. cd 1/2/3
88
- # get new target for 1/2 and find candidates for 3
89
- path, input = build_path(input)
90
-
91
- # We silence warnings here or Ruby 1.8 cries about "multiple values for
92
- # block 0 for 1".
93
- Helpers::BaseHelpers.silence_warnings do
94
- unless path.call.empty?
95
- target = begin
96
- ctx = Helpers::BaseHelpers.context_from_object_path(path.call, pry)
97
- ctx.first
98
- rescue Pry::CommandError
99
- []
100
- end
101
- target = target.last
102
- end
103
- end
104
-
105
- begin
106
- bind = target
107
-
108
- case input
109
-
110
-
111
- # Complete stdlib symbols
112
-
113
- when /^(\/[^\/]*\/)\.([^.]*)$/
114
- # Regexp
115
- receiver = $1
116
- message = Regexp.quote($2)
117
-
118
- candidates = Regexp.instance_methods.collect(&:to_s)
119
- select_message(path, receiver, message, candidates)
120
-
121
- when /^([^\]]*\])\.([^.]*)$/
122
- # Array
123
- receiver = $1
124
- message = Regexp.quote($2)
125
-
126
- candidates = Array.instance_methods.collect(&:to_s)
127
- select_message(path, receiver, message, candidates)
128
-
129
- when /^([^\}]*\})\.([^.]*)$/
130
- # Proc or Hash
131
- receiver = $1
132
- message = Regexp.quote($2)
133
-
134
- candidates = Proc.instance_methods.collect(&:to_s)
135
- candidates |= Hash.instance_methods.collect(&:to_s)
136
- select_message(path, receiver, message, candidates)
137
-
138
- when /^(:[^:.]*)$/
139
- # Symbol
140
- if Symbol.respond_to?(:all_symbols)
141
- sym = Regexp.quote($1)
142
- candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
143
-
144
- candidates.grep(/^#{sym}/)
145
- else
146
- []
147
- end
148
-
149
- when /^::([A-Z][^:\.\(]*)$/
150
- # Absolute Constant or class methods
151
- receiver = $1
152
- candidates = Object.constants.collect(&:to_s)
153
- candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
154
-
155
-
156
- # Complete target symbols
157
-
158
- when /^([A-Z][A-Za-z0-9]*)$/
159
- # Constant
160
- message = $1
161
-
162
- begin
163
- context = target.eval("self")
164
- context = context.class unless context.respond_to? :constants
165
- candidates = context.constants.collect(&:to_s)
166
- rescue
167
- candidates = []
168
- end
169
- candidates = candidates.grep(/^#{message}/).collect(&path)
170
-
171
- when /^([A-Z].*)::([^:.]*)$/
172
- # Constant or class methods
173
- receiver = $1
174
- message = Regexp.quote($2)
175
- begin
176
- candidates = eval("#{receiver}.constants.collect(&:to_s)", bind)
177
- candidates |= eval("#{receiver}.methods.collect(&:to_s)", bind)
178
- rescue RescuableException
179
- candidates = []
180
- end
181
- candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e}
182
-
183
- when /^(:[^:.]+)\.([^.]*)$/
184
- # Symbol
185
- receiver = $1
186
- message = Regexp.quote($2)
187
-
188
- candidates = Symbol.instance_methods.collect(&:to_s)
189
- select_message(path, receiver, message, candidates)
190
-
191
- when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/
192
- # Numeric
193
- receiver = $1
194
- message = Regexp.quote($5)
195
-
196
- begin
197
- candidates = eval(receiver, bind).methods.collect(&:to_s)
198
- rescue RescuableException
199
- candidates = []
200
- end
201
- select_message(path, receiver, message, candidates)
202
-
203
- when /^(-?0x[0-9a-fA-F_]+)\.([^.]*)$/#
204
- # Numeric(0xFFFF)
205
- receiver = $1
206
- message = Regexp.quote($2)
207
-
208
- begin
209
- candidates = eval(receiver, bind).methods.collect(&:to_s)
210
- rescue RescuableException
211
- candidates = []
212
- end
213
- select_message(path, receiver, message, candidates)
214
-
215
- when /^(\$[^.]*)$/
216
- # Global variables
217
- regmessage = Regexp.new(Regexp.quote($1))
218
- candidates = global_variables.collect(&:to_s).grep(regmessage)
219
-
220
- when /^([^."].*)\.([^.]*)$/
221
- # Variable
222
- receiver = $1
223
- message = Regexp.quote($2)
224
-
225
- gv = eval("global_variables", bind).collect(&:to_s)
226
- lv = eval("local_variables", bind).collect(&:to_s)
227
- cv = eval("self.class.constants", bind).collect(&:to_s)
228
-
229
- if (gv | lv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
230
- # foo.func and foo is local var. OR
231
- # Foo::Bar.func
232
- begin
233
- candidates = eval("#{receiver}.methods", bind).collect(&:to_s)
234
- rescue RescuableException
235
- candidates = []
236
- end
237
- else
238
- # func1.func2
239
- candidates = []
240
- ObjectSpace.each_object(Module){|m|
241
- begin
242
- name = m.name.to_s
243
- rescue RescuableException
244
- name = ""
245
- end
246
- next if name != "IRB::Context" and
247
- /^(IRB|SLex|RubyLex|RubyToken)/ =~ name
248
-
249
- # jruby doesn't always provide #instance_methods() on each
250
- # object.
251
- if m.respond_to?(:instance_methods)
252
- candidates.concat m.instance_methods(false).collect(&:to_s)
253
- end
254
- }
255
- candidates.sort!
256
- candidates.uniq!
257
- end
258
- select_message(path, receiver, message, candidates)
259
-
260
- when /^\.([^.]*)$/
261
- # Unknown(maybe String)
262
- receiver = ""
263
- message = Regexp.quote($1)
264
-
265
- candidates = String.instance_methods(true).collect(&:to_s)
266
- select_message(path, receiver, message, candidates)
267
-
268
- else
269
-
270
- candidates = eval(
271
- "methods | private_methods | local_variables | " \
272
- "self.class.constants | instance_variables",
273
- bind
274
- ).collect(&:to_s)
275
-
276
- if eval("respond_to?(:class_variables)", bind)
277
- candidates += eval("class_variables", bind).collect(&:to_s)
278
- end
279
- candidates = (candidates|ReservedWords|commands).grep(/^#{Regexp.quote(input)}/)
280
- candidates.collect(&path)
281
- end
282
- rescue RescuableException
283
- []
284
- end
285
- end
286
- end
287
-
288
- def self.select_message(path, receiver, message, candidates)
289
- candidates.grep(/^#{message}/).collect { |e|
290
- case e
291
- when /^[a-zA-Z_]/
292
- path.call(receiver + "." + e)
293
- when /^[0-9]/
294
- when *Operators
295
- #receiver + " " + e
296
- end
297
- }.compact
298
- end
299
-
300
- # build_path seperates the input into two parts: path and input.
301
- # input is the partial string that should be completed
302
- # path is a proc that takes an input and builds a full path.
303
- def self.build_path(input)
304
-
305
- # check to see if the input is a regex
306
- return proc {|input| input.to_s }, input if input[/\/\./]
307
-
308
- trailing_slash = input.end_with?('/')
309
- contexts = input.chomp('/').split(/\//)
310
- input = contexts[-1]
311
-
312
- path = Proc.new do |input|
313
- p = contexts[0..-2].push(input).join('/')
314
- p += '/' if trailing_slash && !input.nil?
315
- p
316
- end
317
-
318
- return path, input
319
- end
320
- end
321
- end