pry 0.10.pre.1-java → 0.10.0.pre2-java

Sign up to get free protection for your applications and to get access to all the features.
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 +126 -182
  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,25 @@
1
+ class Pry
2
+ class Command::Edit
3
+ class ExceptionPatcher
4
+ attr_accessor :_pry_
5
+ attr_accessor :state
6
+ attr_accessor :file_and_line
7
+
8
+ def initialize(_pry_, state, exception_file_and_line)
9
+ @_pry_ = _pry_
10
+ @state = state
11
+ @file_and_line = exception_file_and_line
12
+ end
13
+
14
+ # perform the patch
15
+ def perform_patch
16
+ file_name, _ = file_and_line
17
+ lines = state.dynamical_ex_file || File.read(file_name)
18
+
19
+ source = Pry::Editor.new(_pry_).edit_tempfile_with_content(lines)
20
+ _pry_.evaluate_ruby source
21
+ state.dynamical_ex_file = source.split("\n")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ class Pry
2
+ class Command::Edit
3
+ module FileAndLineLocator
4
+ class << self
5
+ def from_binding(target)
6
+ [target.eval("__FILE__"), target.eval("__LINE__")]
7
+ end
8
+
9
+ def from_code_object(code_object, filename_argument)
10
+ if File.exists?(code_object.source_file.to_s)
11
+ [code_object.source_file, code_object.source_line]
12
+ else
13
+ raise CommandError, "Cannot find a file for #{filename_argument}!"
14
+ end
15
+ end
16
+
17
+ def from_exception(exception, backtrace_level)
18
+ raise CommandError, "No exception found." if exception.nil?
19
+
20
+ file_name, line = exception.bt_source_location_for(backtrace_level)
21
+ raise CommandError, "Exception has no associated file." if file_name.nil?
22
+ raise CommandError, "Cannot edit exceptions raised in REPL." if Pry.eval_path == file_name
23
+
24
+ [file_name, line]
25
+ end
26
+
27
+ # when file and line are passed as a single arg, e.g my_file.rb:30
28
+ def from_filename_argument(filename_argument)
29
+ f = File.expand_path(filename_argument)
30
+ l = f.sub!(/:(\d+)$/, "") ? $1.to_i : 1
31
+ [f, l]
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,42 @@
1
+ class Pry
2
+ class Command::Exit < Pry::ClassCommand
3
+ match 'exit'
4
+ group 'Navigating Pry'
5
+ description 'Pop the previous binding.'
6
+ command_options :keep_retval => true
7
+
8
+ banner <<-'BANNER'
9
+ Usage: exit [OPTIONS] [--help]
10
+ Aliases: quit
11
+
12
+ Pop the previous binding (does NOT exit program). It can be useful to exit a
13
+ context with a user-provided value. For instance an exit value can be used to
14
+ determine program flow.
15
+
16
+ exit "pry this"
17
+ exit
18
+
19
+ https://github.com/pry/pry/wiki/State-navigation#wiki-Exit_with_value
20
+ BANNER
21
+
22
+ def process
23
+ if _pry_.binding_stack.one?
24
+ _pry_.run_command "exit-all #{arg_string}"
25
+ else
26
+ # otherwise just pop a binding and return user supplied value
27
+ process_pop_and_return
28
+ end
29
+ end
30
+
31
+ def process_pop_and_return
32
+ popped_object = _pry_.binding_stack.pop.eval('self')
33
+
34
+ # return a user-specified value if given otherwise return the object
35
+ return target.eval(arg_string) unless arg_string.empty?
36
+ popped_object
37
+ end
38
+ end
39
+
40
+ Pry::Commands.add_command(Pry::Command::Exit)
41
+ Pry::Commands.alias_command 'quit', 'exit'
42
+ end
@@ -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