pry 0.10.pre.1-i386-mingw32 → 0.10.0.pre3-i386-mingw32

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 (214) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +41 -35
  5. data/lib/pry.rb +82 -139
  6. data/lib/pry/cli.rb +77 -30
  7. data/lib/pry/code.rb +122 -183
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +71 -0
  10. data/lib/pry/code/loc.rb +92 -0
  11. data/lib/pry/code_object.rb +172 -0
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +184 -28
  14. data/lib/pry/command_set.rb +113 -59
  15. data/lib/pry/commands.rb +4 -27
  16. data/lib/pry/commands/amend_line.rb +99 -0
  17. data/lib/pry/commands/bang.rb +20 -0
  18. data/lib/pry/commands/bang_pry.rb +17 -0
  19. data/lib/pry/commands/cat.rb +62 -0
  20. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  21. data/lib/pry/commands/cat/exception_formatter.rb +77 -0
  22. data/lib/pry/commands/cat/file_formatter.rb +67 -0
  23. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  24. data/lib/pry/commands/cd.rb +41 -0
  25. data/lib/pry/commands/change_inspector.rb +27 -0
  26. data/lib/pry/commands/change_prompt.rb +26 -0
  27. data/lib/pry/commands/code_collector.rb +165 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/disabled_commands.rb +2 -0
  30. data/lib/pry/commands/easter_eggs.rb +112 -0
  31. data/lib/pry/commands/edit.rb +195 -0
  32. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
  34. data/lib/pry/commands/exit.rb +42 -0
  35. data/lib/pry/commands/exit_all.rb +29 -0
  36. data/lib/pry/commands/exit_program.rb +23 -0
  37. data/lib/pry/commands/find_method.rb +193 -0
  38. data/lib/pry/commands/fix_indent.rb +19 -0
  39. data/lib/pry/commands/gem_cd.rb +26 -0
  40. data/lib/pry/commands/gem_install.rb +32 -0
  41. data/lib/pry/commands/gem_list.rb +33 -0
  42. data/lib/pry/commands/gem_open.rb +29 -0
  43. data/lib/pry/commands/gist.rb +101 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +180 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +53 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/list_inspectors.rb +35 -0
  50. data/lib/pry/commands/list_prompts.rb +35 -0
  51. data/lib/pry/commands/ls.rb +114 -0
  52. data/lib/pry/commands/ls/constants.rb +47 -0
  53. data/lib/pry/commands/ls/formatter.rb +49 -0
  54. data/lib/pry/commands/ls/globals.rb +48 -0
  55. data/lib/pry/commands/ls/grep.rb +21 -0
  56. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  57. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  58. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  59. data/lib/pry/commands/ls/local_names.rb +35 -0
  60. data/lib/pry/commands/ls/local_vars.rb +39 -0
  61. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  62. data/lib/pry/commands/ls/methods.rb +57 -0
  63. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  64. data/lib/pry/commands/ls/self_methods.rb +32 -0
  65. data/lib/pry/commands/nesting.rb +25 -0
  66. data/lib/pry/commands/play.rb +103 -0
  67. data/lib/pry/commands/pry_backtrace.rb +25 -0
  68. data/lib/pry/commands/pry_version.rb +17 -0
  69. data/lib/pry/commands/raise_up.rb +32 -0
  70. data/lib/pry/commands/reload_code.rb +62 -0
  71. data/lib/pry/commands/reset.rb +18 -0
  72. data/lib/pry/commands/ri.rb +60 -0
  73. data/lib/pry/commands/save_file.rb +61 -0
  74. data/lib/pry/commands/shell_command.rb +48 -0
  75. data/lib/pry/commands/shell_mode.rb +25 -0
  76. data/lib/pry/commands/show_doc.rb +83 -0
  77. data/lib/pry/commands/show_info.rb +195 -0
  78. data/lib/pry/commands/show_input.rb +17 -0
  79. data/lib/pry/commands/show_source.rb +50 -0
  80. data/lib/pry/commands/simple_prompt.rb +22 -0
  81. data/lib/pry/commands/stat.rb +40 -0
  82. data/lib/pry/commands/switch_to.rb +23 -0
  83. data/lib/pry/commands/toggle_color.rb +24 -0
  84. data/lib/pry/commands/watch_expression.rb +105 -0
  85. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  86. data/lib/pry/commands/whereami.rb +190 -0
  87. data/lib/pry/commands/wtf.rb +57 -0
  88. data/lib/pry/config.rb +20 -229
  89. data/lib/pry/config/behavior.rb +139 -0
  90. data/lib/pry/config/convenience.rb +26 -0
  91. data/lib/pry/config/default.rb +165 -0
  92. data/lib/pry/core_extensions.rb +59 -38
  93. data/lib/pry/editor.rb +133 -0
  94. data/lib/pry/exceptions.rb +77 -0
  95. data/lib/pry/helpers.rb +1 -0
  96. data/lib/pry/helpers/base_helpers.rb +40 -154
  97. data/lib/pry/helpers/command_helpers.rb +19 -130
  98. data/lib/pry/helpers/documentation_helpers.rb +21 -11
  99. data/lib/pry/helpers/table.rb +109 -0
  100. data/lib/pry/helpers/text.rb +8 -9
  101. data/lib/pry/history.rb +61 -45
  102. data/lib/pry/history_array.rb +11 -1
  103. data/lib/pry/hooks.rb +10 -32
  104. data/lib/pry/indent.rb +110 -38
  105. data/lib/pry/input_completer.rb +242 -0
  106. data/lib/pry/input_lock.rb +132 -0
  107. data/lib/pry/inspector.rb +27 -0
  108. data/lib/pry/last_exception.rb +61 -0
  109. data/lib/pry/method.rb +199 -200
  110. data/lib/pry/method/disowned.rb +53 -0
  111. data/lib/pry/method/patcher.rb +125 -0
  112. data/lib/pry/method/weird_method_locator.rb +186 -0
  113. data/lib/pry/module_candidate.rb +39 -33
  114. data/lib/pry/object_path.rb +82 -0
  115. data/lib/pry/output.rb +50 -0
  116. data/lib/pry/pager.rb +234 -0
  117. data/lib/pry/plugins.rb +4 -3
  118. data/lib/pry/prompt.rb +26 -0
  119. data/lib/pry/pry_class.rb +199 -227
  120. data/lib/pry/pry_instance.rb +344 -403
  121. data/lib/pry/rbx_path.rb +1 -1
  122. data/lib/pry/repl.rb +202 -0
  123. data/lib/pry/repl_file_loader.rb +20 -26
  124. data/lib/pry/rubygem.rb +82 -0
  125. data/lib/pry/terminal.rb +79 -0
  126. data/lib/pry/test/helper.rb +170 -0
  127. data/lib/pry/version.rb +1 -1
  128. data/lib/pry/wrapped_module.rb +133 -48
  129. metadata +132 -197
  130. data/.document +0 -2
  131. data/.gemtest +0 -0
  132. data/.gitignore +0 -16
  133. data/.travis.yml +0 -17
  134. data/.yardopts +0 -1
  135. data/CHANGELOG +0 -387
  136. data/CONTRIBUTORS +0 -36
  137. data/Gemfile +0 -2
  138. data/Rakefile +0 -137
  139. data/TODO +0 -117
  140. data/examples/example_basic.rb +0 -15
  141. data/examples/example_command_override.rb +0 -32
  142. data/examples/example_commands.rb +0 -36
  143. data/examples/example_hooks.rb +0 -9
  144. data/examples/example_image_edit.rb +0 -67
  145. data/examples/example_input.rb +0 -7
  146. data/examples/example_input2.rb +0 -29
  147. data/examples/example_output.rb +0 -11
  148. data/examples/example_print.rb +0 -6
  149. data/examples/example_prompt.rb +0 -9
  150. data/examples/helper.rb +0 -6
  151. data/lib/pry/completion.rb +0 -221
  152. data/lib/pry/custom_completions.rb +0 -6
  153. data/lib/pry/default_commands/cd.rb +0 -81
  154. data/lib/pry/default_commands/commands.rb +0 -62
  155. data/lib/pry/default_commands/context.rb +0 -98
  156. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  157. data/lib/pry/default_commands/editing.rb +0 -420
  158. data/lib/pry/default_commands/find_method.rb +0 -169
  159. data/lib/pry/default_commands/gems.rb +0 -84
  160. data/lib/pry/default_commands/gist.rb +0 -187
  161. data/lib/pry/default_commands/help.rb +0 -127
  162. data/lib/pry/default_commands/hist.rb +0 -120
  163. data/lib/pry/default_commands/input_and_output.rb +0 -306
  164. data/lib/pry/default_commands/introspection.rb +0 -410
  165. data/lib/pry/default_commands/ls.rb +0 -272
  166. data/lib/pry/default_commands/misc.rb +0 -38
  167. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  168. data/lib/pry/default_commands/whereami.rb +0 -92
  169. data/lib/pry/extended_commands/experimental.rb +0 -7
  170. data/lib/pry/rbx_method.rb +0 -13
  171. data/man/pry.1 +0 -195
  172. data/man/pry.1.html +0 -204
  173. data/man/pry.1.ronn +0 -141
  174. data/pry.gemspec +0 -46
  175. data/test/candidate_helper1.rb +0 -11
  176. data/test/candidate_helper2.rb +0 -8
  177. data/test/helper.rb +0 -223
  178. data/test/test_cli.rb +0 -78
  179. data/test/test_code.rb +0 -201
  180. data/test/test_command.rb +0 -712
  181. data/test/test_command_helpers.rb +0 -9
  182. data/test/test_command_integration.rb +0 -668
  183. data/test/test_command_set.rb +0 -610
  184. data/test/test_completion.rb +0 -62
  185. data/test/test_control_d_handler.rb +0 -45
  186. data/test/test_default_commands/example.erb +0 -5
  187. data/test/test_default_commands/test_cd.rb +0 -318
  188. data/test/test_default_commands/test_context.rb +0 -280
  189. data/test/test_default_commands/test_documentation.rb +0 -314
  190. data/test/test_default_commands/test_find_method.rb +0 -50
  191. data/test/test_default_commands/test_gems.rb +0 -18
  192. data/test/test_default_commands/test_help.rb +0 -57
  193. data/test/test_default_commands/test_input.rb +0 -428
  194. data/test/test_default_commands/test_introspection.rb +0 -511
  195. data/test/test_default_commands/test_ls.rb +0 -151
  196. data/test/test_default_commands/test_shell.rb +0 -343
  197. data/test/test_default_commands/test_show_source.rb +0 -432
  198. data/test/test_exception_whitelist.rb +0 -21
  199. data/test/test_history_array.rb +0 -65
  200. data/test/test_hooks.rb +0 -521
  201. data/test/test_indent.rb +0 -277
  202. data/test/test_input_stack.rb +0 -86
  203. data/test/test_method.rb +0 -401
  204. data/test/test_pry.rb +0 -463
  205. data/test/test_pry_defaults.rb +0 -419
  206. data/test/test_pry_history.rb +0 -84
  207. data/test/test_pry_output.rb +0 -41
  208. data/test/test_sticky_locals.rb +0 -155
  209. data/test/test_syntax_checking.rb +0 -65
  210. data/test/test_wrapped_module.rb +0 -174
  211. data/test/testrc +0 -2
  212. data/test/testrcbad +0 -2
  213. data/wiki/Customizing-pry.md +0 -397
  214. data/wiki/Home.md +0 -4
@@ -0,0 +1,195 @@
1
+ class Pry
2
+ class Command::ShowInfo < Pry::ClassCommand
3
+ extend Pry::Helpers::BaseHelpers
4
+
5
+ command_options :shellwords => false, :interpolate => false
6
+
7
+ def options(opt)
8
+ opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors", :as => :count
9
+ opt.on :l, "line-numbers", "Show line numbers"
10
+ opt.on :b, "base-one", "Show line numbers but start numbering at 1 (useful for `amend-line` and `play` commands)"
11
+ opt.on :a, :all, "Show all definitions and monkeypatches of the module/class"
12
+ end
13
+
14
+ def process
15
+ code_object = Pry::CodeObject.lookup(obj_name, _pry_, :super => opts[:super])
16
+ raise CommandError, no_definition_message if !code_object
17
+ @original_code_object = code_object
18
+
19
+ if show_all_modules?(code_object)
20
+ # show all monkey patches for a module
21
+
22
+ result = content_and_headers_for_all_module_candidates(code_object)
23
+ else
24
+ # show a specific code object
25
+ co = code_object_with_accessible_source(code_object)
26
+ result = content_and_header_for_code_object(co)
27
+ end
28
+
29
+ set_file_and_dir_locals(code_object.source_file)
30
+ _pry_.pager.page result
31
+ end
32
+
33
+ # This method checks whether the `code_object` is a WrappedModule,
34
+ # if it is, then it returns the first candidate (monkeypatch) with
35
+ # accessible source (or docs). If `code_object` is not a WrappedModule (i.e a
36
+ # method or a command) then the `code_object` itself is just
37
+ # returned.
38
+ #
39
+ # @return [Pry::WrappedModule, Pry::Method, Pry::Command]
40
+ def code_object_with_accessible_source(code_object)
41
+ if code_object.is_a?(WrappedModule)
42
+ candidate = code_object.candidates.find(&:source)
43
+ if candidate
44
+ return candidate
45
+ else
46
+ raise CommandError, no_definition_message if !valid_superclass?(code_object)
47
+
48
+ @used_super = true
49
+ code_object_with_accessible_source(code_object.super)
50
+ end
51
+ else
52
+ code_object
53
+ end
54
+ end
55
+
56
+ def valid_superclass?(code_object)
57
+ code_object.super && code_object.super.wrapped != Object
58
+ end
59
+
60
+ def content_and_header_for_code_object(code_object)
61
+ header(code_object) << content_for(code_object)
62
+ end
63
+
64
+ def content_and_headers_for_all_module_candidates(mod)
65
+ result = "Found #{mod.number_of_candidates} candidates for `#{mod.name}` definition:\n"
66
+ mod.number_of_candidates.times do |v|
67
+ candidate = mod.candidate(v)
68
+ begin
69
+ result << "\nCandidate #{v+1}/#{mod.number_of_candidates}: #{candidate.source_file} @ line #{candidate.source_line}:\n"
70
+ content = content_for(candidate)
71
+
72
+ result << "Number of lines: #{content.lines.count}\n\n" << content
73
+ rescue Pry::RescuableException
74
+ result << "\nNo content found.\n"
75
+ next
76
+ end
77
+ end
78
+ result
79
+ end
80
+
81
+ def no_definition_message
82
+ "Couldn't locate a definition for #{obj_name}!"
83
+ end
84
+
85
+ # Generate a header (meta-data information) for all the code
86
+ # object types: methods, modules, commands, procs...
87
+ def header(code_object)
88
+ file_name, line_num = file_and_line_for(code_object)
89
+ h = "\n#{Pry::Helpers::Text.bold('From:')} #{file_name} "
90
+ h << code_object_header(code_object, line_num)
91
+ h << "\n#{Pry::Helpers::Text.bold('Number of lines:')} " <<
92
+ "#{content_for(code_object).lines.count}\n\n"
93
+ h << Helpers::Text.bold('** Warning:') << " Cannot find code for #{@original_code_object.nonblank_name}. Showing superclass #{code_object.nonblank_name} instead. **\n\n" if @used_super
94
+ h
95
+ end
96
+
97
+ def code_object_header(code_object, line_num)
98
+ if code_object.real_method_object?
99
+ method_header(code_object, line_num)
100
+
101
+ # It sucks we have to test for both Pry::WrappedModule and WrappedModule::Candidate,
102
+ # probably indicates a deep refactor needs to happen in those classes.
103
+ elsif code_object.is_a?(Pry::WrappedModule) || code_object.is_a?(Pry::WrappedModule::Candidate)
104
+ module_header(code_object, line_num)
105
+ else
106
+ ""
107
+ end
108
+ end
109
+
110
+ def method_header(code_object, line_num)
111
+ h = ""
112
+ h << (code_object.c_method? ? "(C Method):" : "@ line #{line_num}:")
113
+ h << method_sections(code_object)[:owner]
114
+ h << method_sections(code_object)[:visibility]
115
+ h << method_sections(code_object)[:signature]
116
+ h
117
+ end
118
+
119
+ def module_header(code_object, line_num)
120
+ h = ""
121
+ h << "@ line #{line_num}:\n"
122
+ h << text.bold(code_object.module? ? "Module" : "Class")
123
+ h << " #{text.bold('name:')} #{code_object.nonblank_name}"
124
+
125
+ if code_object.number_of_candidates > 1
126
+ h << (text.bold("\nNumber of monkeypatches: ") << code_object.number_of_candidates.to_s)
127
+ h << ". Use the `-a` option to display all available monkeypatches"
128
+ end
129
+ h
130
+ end
131
+
132
+ def method_sections(code_object)
133
+ {
134
+ :owner => "\n#{text.bold("Owner:")} #{code_object.owner || "N/A"}\n",
135
+ :visibility => "#{text.bold("Visibility:")} #{code_object.visibility}",
136
+ :signature => "\n#{text.bold("Signature:")} #{code_object.signature}"
137
+ }.merge(header_options) { |key, old, new| (new && old).to_s }
138
+ end
139
+
140
+ def header_options
141
+ {
142
+ :owner => true,
143
+ :visibility => true,
144
+ :signature => nil
145
+ }
146
+ end
147
+
148
+ def show_all_modules?(code_object)
149
+ code_object.is_a?(Pry::WrappedModule) && opts.present?(:all)
150
+ end
151
+
152
+ def obj_name
153
+ @obj_name ||= args.empty? ? nil : args.join(' ')
154
+ end
155
+
156
+ def use_line_numbers?
157
+ opts.present?(:b) || opts.present?(:l)
158
+ end
159
+
160
+ def start_line_for(code_object)
161
+ if opts.present?(:'base-one')
162
+ 1
163
+ else
164
+ code_object.source_line || 1
165
+ end
166
+ end
167
+
168
+ # takes into account possible yard docs, and returns yard_file / yard_line
169
+ # Also adjusts for start line of comments (using start_line_for), which it has to infer
170
+ # by subtracting number of lines of comment from start line of code_object
171
+ def file_and_line_for(code_object)
172
+ if code_object.module_with_yard_docs?
173
+ [code_object.yard_file, code_object.yard_line]
174
+ else
175
+ [code_object.source_file, start_line_for(code_object)]
176
+ end
177
+ end
178
+
179
+ def complete(input)
180
+ if input =~ /([^ ]*)#([a-z0-9_]*)\z/
181
+ prefix, search = [$1, $2]
182
+ methods = begin
183
+ Pry::Method.all_from_class(binding.eval(prefix))
184
+ rescue RescuableException
185
+ return super
186
+ end
187
+ methods.map do |method|
188
+ [prefix, method.name].join('#') if method.name.start_with?(search)
189
+ end.compact
190
+ else
191
+ super
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,17 @@
1
+ class Pry
2
+ class Command::ShowInput < Pry::ClassCommand
3
+ match 'show-input'
4
+ group 'Editing'
5
+ description 'Show the contents of the input buffer for the current multi-line expression.'
6
+
7
+ banner <<-'BANNER'
8
+ Show the contents of the input buffer for the current multi-line expression.
9
+ BANNER
10
+
11
+ def process
12
+ output.puts Code.new(eval_string).with_line_numbers
13
+ end
14
+ end
15
+
16
+ Pry::Commands.add_command(Pry::Command::ShowInput)
17
+ end
@@ -0,0 +1,50 @@
1
+ require 'pry/commands/show_info'
2
+
3
+ class Pry
4
+ class Command::ShowSource < Command::ShowInfo
5
+ match 'show-source'
6
+ group 'Introspection'
7
+ description 'Show the source for a method or class.'
8
+
9
+ banner <<-'BANNER'
10
+ Usage: show-source [OPTIONS] [METH|CLASS]
11
+ Aliases: $, show-method
12
+
13
+ Show the source for a method or class. Tries instance methods first and then
14
+ methods by default.
15
+
16
+ show-source hi_method
17
+ show-source hi_method
18
+ show-source Pry#rep # source for Pry#rep method
19
+ show-source Pry # for Pry class
20
+ show-source Pry -a # for all Pry class definitions (all monkey patches)
21
+ show-source Pry.foo -e # for class of the return value of expression `Pry.foo`
22
+ show-source Pry --super # for superclass of Pry (Object class)
23
+
24
+ https://github.com/pry/pry/wiki/Source-browsing#wiki-Show_method
25
+ BANNER
26
+
27
+ def options(opt)
28
+ opt.on :e, :eval, "evaluate the command's argument as a ruby expression and show the class its return value"
29
+ super(opt)
30
+ end
31
+
32
+ def process
33
+ if opts.present?(:e)
34
+ obj = target.eval(args.first)
35
+ self.args = Array.new(1) { Module === obj ? obj.name : obj.class.name }
36
+ end
37
+ super
38
+ end
39
+
40
+ # The source for code_object prepared for display.
41
+ def content_for(code_object)
42
+ Code.new(code_object.source, start_line_for(code_object)).
43
+ with_line_numbers(use_line_numbers?)
44
+ end
45
+ end
46
+
47
+ Pry::Commands.add_command(Pry::Command::ShowSource)
48
+ Pry::Commands.alias_command 'show-method', 'show-source'
49
+ Pry::Commands.alias_command '$', 'show-source'
50
+ end
@@ -0,0 +1,22 @@
1
+ class Pry
2
+ class Command::SimplePrompt < Pry::ClassCommand
3
+ match 'simple-prompt'
4
+ group 'prompts'
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
@@ -0,0 +1,40 @@
1
+ class Pry
2
+ class Command::Stat < Pry::ClassCommand
3
+ match 'stat'
4
+ group 'Introspection'
5
+ description 'View method information and set _file_ and _dir_ locals.'
6
+ command_options :shellwords => false
7
+
8
+ banner <<-'BANNER'
9
+ Usage: stat [OPTIONS] [METH]
10
+
11
+ Show method information for method METH and set _file_ and _dir_ locals.
12
+
13
+ stat hello_method
14
+ BANNER
15
+
16
+ def options(opt)
17
+ method_options(opt)
18
+ end
19
+
20
+ def process
21
+ meth = method_object
22
+ aliases = meth.aliases
23
+
24
+ output.puts unindent <<-EOS
25
+ Method Information:
26
+ --
27
+ Name: #{meth.name}
28
+ Alias#{ "es" if aliases.length > 1 }: #{ aliases.any? ? aliases.join(", ") : "None." }
29
+ Owner: #{meth.owner ? meth.owner : "Unknown"}
30
+ Visibility: #{meth.visibility}
31
+ Type: #{meth.is_a?(::Method) ? "Bound" : "Unbound"}
32
+ Arity: #{meth.arity}
33
+ Method Signature: #{meth.signature}
34
+ Source Location: #{meth.source_location ? meth.source_location.join(":") : "Not found."}
35
+ EOS
36
+ end
37
+ end
38
+
39
+ Pry::Commands.add_command(Pry::Command::Stat)
40
+ end
@@ -0,0 +1,23 @@
1
+ class Pry
2
+ class Command::SwitchTo < Pry::ClassCommand
3
+ match 'switch-to'
4
+ group 'Navigating Pry'
5
+ description 'Start a new subsession on a binding in the current stack.'
6
+
7
+ banner <<-'BANNER'
8
+ Start a new subsession on a binding in the current stack (numbered by nesting).
9
+ BANNER
10
+
11
+ def process(selection)
12
+ selection = selection.to_i
13
+
14
+ if selection < 0 || selection > _pry_.binding_stack.size - 1
15
+ raise CommandError, "Invalid binding index #{selection} - use `nesting` command to view valid indices."
16
+ else
17
+ Pry.start(_pry_.binding_stack[selection])
18
+ end
19
+ end
20
+ end
21
+
22
+ Pry::Commands.add_command(Pry::Command::SwitchTo)
23
+ end
@@ -0,0 +1,24 @@
1
+ class Pry
2
+ class Command::ToggleColor < Pry::ClassCommand
3
+ match 'toggle-color'
4
+ group 'Misc'
5
+ description 'Toggle syntax highlighting.'
6
+
7
+ banner <<-'BANNER'
8
+ Usage: toggle-color
9
+
10
+ Toggle syntax highlighting.
11
+ BANNER
12
+
13
+ def process
14
+ _pry_.color = color_toggle
15
+ output.puts "Syntax highlighting #{_pry_.color ? "on" : "off"}"
16
+ end
17
+
18
+ def color_toggle
19
+ !_pry_.color
20
+ end
21
+
22
+ Pry::Commands.add_command(self)
23
+ end
24
+ end
@@ -0,0 +1,105 @@
1
+ class Pry
2
+ class Command::WatchExpression < Pry::ClassCommand
3
+ require 'pry/commands/watch_expression/expression.rb'
4
+
5
+ match 'watch'
6
+ group 'Context'
7
+ description 'Watch the value of an expression and print a notification whenever it changes.'
8
+ command_options :use_prefix => false
9
+
10
+ banner <<-'BANNER'
11
+ Usage: watch [EXPRESSION]
12
+ watch
13
+ watch --delete [INDEX]
14
+
15
+ watch [EXPRESSION] adds an expression to the list of those being watched.
16
+ It will be re-evaluated every time you hit enter in pry. If its value has
17
+ changed, the new value will be printed to the console.
18
+
19
+ This is useful if you are step-through debugging and want to see how
20
+ something changes over time. It's also useful if you're trying to write
21
+ a method inside pry and want to check that it gives the right answers
22
+ every time you redefine it.
23
+
24
+ watch on its own displays all the currently watched expressions and their
25
+ values, and watch --delete [INDEX] allows you to delete expressions from
26
+ the list being watched.
27
+ BANNER
28
+
29
+ def options(opt)
30
+ opt.on :d, :delete,
31
+ "Delete the watch expression with the given index. If no index is given; clear all watch expressions.",
32
+ :optional_argument => true, :as => Integer
33
+ opt.on :l, :list,
34
+ "Show all current watch expressions and their values. Calling watch with no expressions or options will also show the watch expressions."
35
+ end
36
+
37
+ def process
38
+ case
39
+ when opts.present?(:delete)
40
+ delete opts[:delete]
41
+ when opts.present?(:list) || args.empty?
42
+ list
43
+ else
44
+ add_hook
45
+ add_expression(args)
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def expressions
52
+ _pry_.config.watch_expressions ||= []
53
+ end
54
+
55
+ def delete(index)
56
+ if index
57
+ output.puts "Deleting watch expression ##{index}: #{expressions[index-1]}"
58
+ expressions.delete_at(index-1)
59
+ else
60
+ output.puts "Deleting all watched expressions"
61
+ expressions.clear
62
+ end
63
+ end
64
+
65
+ def list
66
+ if expressions.empty?
67
+ output.puts "No watched expressions"
68
+ else
69
+ _pry_.pager.open do |pager|
70
+ pager.puts "Listing all watched expressions:"
71
+ pager.puts ""
72
+ expressions.each_with_index do |expr, index|
73
+ pager.print text.with_line_numbers(expr.to_s, index+1)
74
+ end
75
+ pager.puts ""
76
+ end
77
+ end
78
+ end
79
+
80
+ def eval_and_print_changed(output)
81
+ expressions.each do |expr|
82
+ expr.eval!
83
+ if expr.changed?
84
+ output.puts "#{text.blue "watch"}: #{expr.to_s}"
85
+ end
86
+ end
87
+ end
88
+
89
+ def add_expression(arguments)
90
+ expressions << Expression.new(_pry_, target, arg_string)
91
+ output.puts "Watching #{Code.new(arg_string)}"
92
+ end
93
+
94
+ def add_hook
95
+ hook = [:after_eval, :watch_expression]
96
+ unless _pry_.hooks.hook_exists?(*hook)
97
+ _pry_.hooks.add_hook(*hook) do |_, _pry_|
98
+ eval_and_print_changed _pry_.output
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ Pry::Commands.add_command(Pry::Command::WatchExpression)
105
+ end