pry 0.9.12.2 → 0.14.2

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 (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
data/lib/pry/plugins.rb DELETED
@@ -1,103 +0,0 @@
1
- class Pry
2
- class PluginManager
3
- PRY_PLUGIN_PREFIX = /^pry-/
4
-
5
- # Placeholder when no associated gem found, displays warning
6
- class NoPlugin
7
- def initialize(name)
8
- @name = name
9
- end
10
-
11
- def method_missing(*args)
12
- warn "Warning: The plugin '#{@name}' was not found! (no gem found)"
13
- end
14
- end
15
-
16
- class Plugin
17
- attr_accessor :name, :gem_name, :enabled, :spec, :active
18
-
19
- def initialize(name, gem_name, spec, enabled)
20
- @name, @gem_name, @enabled, @spec = name, gem_name, enabled, spec
21
- end
22
-
23
- # Disable a plugin. (prevents plugin from being loaded, cannot
24
- # disable an already activated plugin)
25
- def disable!
26
- self.enabled = false
27
- end
28
-
29
- # Enable a plugin. (does not load it immediately but puts on
30
- # 'white list' to be loaded)
31
- def enable!
32
- self.enabled = true
33
- end
34
-
35
- # Load the Command line options defined by this plugin (if they exist)
36
- def load_cli_options
37
- cli_options_file = File.join(spec.full_gem_path, "lib/#{spec.name}/cli.rb")
38
- require cli_options_file if File.exists?(cli_options_file)
39
- end
40
- # Activate the plugin (require the gem - enables/loads the
41
- # plugin immediately at point of call, even if plugin is
42
- # disabled)
43
- # Does not reload plugin if it's already active.
44
- def activate!
45
- # Create the configuration object for the plugin.
46
- Pry.config.send("#{gem_name.gsub('-', '_')}=", OpenStruct.new)
47
-
48
- begin
49
- require gem_name if !active?
50
- rescue LoadError => e
51
- warn "Found plugin #{gem_name}, but could not require '#{gem_name}'"
52
- warn e
53
- rescue => e
54
- warn "require '#{gem_name}' # Failed, saying: #{e}"
55
- end
56
-
57
- self.active = true
58
- self.enabled = true
59
- end
60
-
61
- alias active? active
62
- alias enabled? enabled
63
- end
64
-
65
- def initialize
66
- @plugins = []
67
- end
68
-
69
- # Find all installed Pry plugins and store them in an internal array.
70
- def locate_plugins
71
- Gem.refresh
72
- (Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')).each do |gem|
73
- next if gem.name !~ PRY_PLUGIN_PREFIX
74
- plugin_name = gem.name.split('-', 2).last
75
- @plugins << Plugin.new(plugin_name, gem.name, gem, true) if !gem_located?(gem.name)
76
- end
77
- @plugins
78
- end
79
-
80
- # @return [Hash] A hash with all plugin names (minus the 'pry-') as
81
- # keys and Plugin objects as values.
82
- def plugins
83
- h = Hash.new { |_, key| NoPlugin.new(key) }
84
- @plugins.each do |plugin|
85
- h[plugin.name] = plugin
86
- end
87
- h
88
- end
89
-
90
- # Require all enabled plugins, disabled plugins are skipped.
91
- def load_plugins
92
- @plugins.each do |plugin|
93
- plugin.activate! if plugin.enabled?
94
- end
95
- end
96
-
97
- private
98
- def gem_located?(gem_name)
99
- @plugins.any? { |plugin| plugin.gem_name == gem_name }
100
- end
101
- end
102
-
103
- end
@@ -1,13 +0,0 @@
1
- class Pry
2
- module RbxMethod
3
- private
4
-
5
- def core_code
6
- MethodSource.source_helper(source_location)
7
- end
8
-
9
- def core_doc
10
- MethodSource.comment_helper(source_location)
11
- end
12
- end
13
- end
data/lib/pry/rbx_path.rb DELETED
@@ -1,22 +0,0 @@
1
- class Pry
2
- module RbxPath
3
- module_function
4
- def is_core_path?(path)
5
- path.start_with?("kernel") || path.start_with?("lib")
6
- end
7
-
8
- def convert_path_to_full(path)
9
- if path.start_with?("kernel")
10
- File.join File.dirname(Rubinius::KERNEL_PATH), path
11
- elsif path.start_with?("lib")
12
- File.join File.dirname(Rubinius::LIB_PATH), path
13
- else
14
- path
15
- end
16
- end
17
-
18
- def rvm_ruby?(path)
19
- !!(path =~ /\.rvm/)
20
- end
21
- end
22
- end
data/lib/pry/rubygem.rb DELETED
@@ -1,74 +0,0 @@
1
- require 'rubygems'
2
-
3
- class Pry
4
- module Rubygem
5
-
6
- class << self
7
- def installed?(name)
8
- if Gem::Specification.respond_to?(:find_all_by_name)
9
- Gem::Specification.find_all_by_name(name).any?
10
- else
11
- Gem.source_index.find_name(name).first
12
- end
13
- end
14
-
15
- # Get the gem spec object for the given gem name.
16
- #
17
- # @param [String] name
18
- # @return [Gem::Specification]
19
- def spec(name)
20
- specs = if Gem::Specification.respond_to?(:each)
21
- Gem::Specification.find_all_by_name(name)
22
- else
23
- Gem.source_index.find_name(name)
24
- end
25
-
26
- spec = specs.sort_by{ |spec| Gem::Version.new(spec.version) }.first
27
-
28
- spec or raise CommandError, "Gem `#{name}` not found"
29
- end
30
-
31
- # List gems matching a pattern.
32
- #
33
- # @param [Regexp] pattern
34
- # @return [Array<Gem::Specification>]
35
- def list(pattern = /.*/)
36
- if Gem::Specification.respond_to?(:each)
37
- Gem::Specification.select{|spec| spec.name =~ pattern }
38
- else
39
- Gem.source_index.gems.values.select{|spec| spec.name =~ pattern }
40
- end
41
- end
42
-
43
- # Completion function for gem-cd and gem-open.
44
- #
45
- # @param [String] so_far what the user's typed so far
46
- # @return [Array<String>] completions
47
- def complete(so_far)
48
- if so_far =~ / ([^ ]*)\z/
49
- self.list(%r{\A#{$2}}).map(&:name)
50
- else
51
- self.list.map(&:name)
52
- end
53
- end
54
-
55
- # Installs a gem with all its dependencies.
56
- #
57
- # @param [String] name
58
- # @return [void]
59
- def install(name)
60
- destination = File.writable?(Gem.dir) ? Gem.dir : Gem.user_dir
61
- installer = Gem::DependencyInstaller.new(:install_dir => destination)
62
- installer.install(name)
63
- rescue Errno::EACCES
64
- raise CommandError,
65
- "Insufficient permissions to install `#{ text.green(name) }`."
66
- rescue Gem::GemNotFoundException
67
- raise CommandError, "Gem `#{ text.green(name) }` not found."
68
- else
69
- Gem.refresh
70
- end
71
- end
72
-
73
- end
74
- end
data/lib/pry/terminal.rb DELETED
@@ -1,78 +0,0 @@
1
- class Pry::Terminal
2
- class << self
3
- # Return a pair of [rows, columns] which gives the size of the window.
4
- #
5
- # If the window size cannot be determined, return nil.
6
- def screen_size
7
- rows, cols = actual_screen_size
8
- if rows && cols
9
- [rows.to_i, cols.to_i]
10
- else
11
- nil
12
- end
13
- end
14
-
15
- # Return a screen size or a default if that fails.
16
- def size! default = [27, 80]
17
- screen_size || default
18
- end
19
-
20
- # Return a screen width or the default if that fails.
21
- def width!
22
- size![1]
23
- end
24
-
25
- # Return a screen height or the default if that fails.
26
- def height!
27
- size![0]
28
- end
29
-
30
- def actual_screen_size
31
- # The best way, if possible (requires non-jruby ≥1.9 or io-console gem)
32
- screen_size_according_to_io_console or
33
- # Fall back to the old standby, though it might be stale:
34
- screen_size_according_to_env or
35
- # Fall further back, though this one is also out of date without something
36
- # calling Readline.set_screen_size
37
- screen_size_according_to_readline or
38
- # Windows users can otherwise run ansicon and get a decent answer:
39
- screen_size_according_to_ansicon_env
40
- end
41
-
42
- def screen_size_according_to_io_console
43
- return if Pry::Helpers::BaseHelpers.jruby?
44
- require 'io/console'
45
- $stdout.winsize if $stdout.tty? and $stdout.respond_to?(:winsize)
46
- rescue LoadError
47
- # They're probably on 1.8 without the io-console gem. We'll keep trying.
48
- end
49
-
50
- def screen_size_according_to_env
51
- size = [ENV['LINES'] || ENV['ROWS'], ENV['COLUMNS']]
52
- size if nonzero_column?(size)
53
- end
54
-
55
- def screen_size_according_to_readline
56
- if Readline.respond_to?(:get_screen_size)
57
- size = Readline.get_screen_size
58
- size if nonzero_column?(size)
59
- end
60
- rescue Java::JavaLang::NullPointerException
61
- # This rescue won't happen on jrubies later than:
62
- # https://github.com/jruby/jruby/pull/436
63
- nil
64
- end
65
-
66
- def screen_size_according_to_ansicon_env
67
- return unless ENV['ANSICON'] =~ /\((.*)x(.*)\)/
68
- size = [$2, $1]
69
- size if nonzero_column?(size)
70
- end
71
-
72
- private
73
-
74
- def nonzero_column?(size)
75
- size[1].to_i > 0
76
- end
77
- end
78
- end
@@ -1,185 +0,0 @@
1
- require 'pry'
2
-
3
- # in case the tests call reset_defaults, ensure we reset them to
4
- # amended (test friendly) values
5
- class << Pry
6
- alias_method :orig_reset_defaults, :reset_defaults
7
- def reset_defaults
8
- orig_reset_defaults
9
-
10
- Pry.color = false
11
- Pry.pager = false
12
- Pry.config.should_load_rc = false
13
- Pry.config.should_load_local_rc= false
14
- Pry.config.should_load_plugins = false
15
- Pry.config.history.should_load = false
16
- Pry.config.history.should_save = false
17
- Pry.config.auto_indent = false
18
- Pry.config.hooks = Pry::Hooks.new
19
- Pry.config.collision_warning = false
20
- end
21
- end
22
- Pry.reset_defaults
23
-
24
- # A global space for storing temporary state during tests.
25
-
26
- module PryTestHelpers
27
-
28
- module_function
29
-
30
- # inject a variable into a binding
31
- def inject_var(name, value, b)
32
- Pry.current[:pry_local] = value
33
- b.eval("#{name} = ::Pry.current[:pry_local]")
34
- ensure
35
- Pry.current[:pry_local] = nil
36
- end
37
-
38
- def constant_scope(*names)
39
- names.each do |name|
40
- Object.remove_const name if Object.const_defined?(name)
41
- end
42
-
43
- yield
44
- ensure
45
- names.each do |name|
46
- Object.remove_const name if Object.const_defined?(name)
47
- end
48
- end
49
-
50
- def mri18_and_no_real_source_location?
51
- Pry::Helpers::BaseHelpers.mri_18? && !(Method.instance_method(:source_location).owner == Method)
52
- end
53
-
54
- # Open a temp file and yield it to the block, closing it after
55
- # @return [String] The path of the temp file
56
- def temp_file(ext='.rb')
57
- file = Tempfile.new(['pry', ext])
58
- yield file
59
- ensure
60
- file.close(true) if file
61
- File.unlink("#{file.path}c") if File.exists?("#{file.path}c") # rbx
62
- end
63
-
64
- def unindent(*args)
65
- Pry::Helpers::CommandHelpers.unindent(*args)
66
- end
67
-
68
- def mock_command(cmd, args=[], opts={})
69
- output = StringIO.new
70
- ret = cmd.new(opts.merge(:output => output)).call_safely(*args)
71
- Struct.new(:output, :return).new(output.string, ret)
72
- end
73
-
74
- def mock_exception(*mock_backtrace)
75
- e = StandardError.new("mock exception")
76
- (class << e; self; end).class_eval do
77
- define_method(:backtrace) { mock_backtrace }
78
- end
79
- e
80
- end
81
- end
82
-
83
- def pry_tester(*args, &block)
84
- if args.length == 0 || args[0].is_a?(Hash)
85
- args.unshift(Pry.toplevel_binding)
86
- end
87
-
88
- PryTester.new(*args).tap do |t|
89
- (class << t; self; end).class_eval(&block) if block
90
- end
91
- end
92
-
93
- def pry_eval(*eval_strs)
94
- if eval_strs.first.is_a? String
95
- binding = Pry.toplevel_binding
96
- else
97
- binding = Pry.binding_for(eval_strs.shift)
98
- end
99
-
100
- pry_tester(binding).eval(*eval_strs)
101
- end
102
-
103
- class PryTester
104
- attr_reader :pry, :out
105
-
106
- def initialize(context = TOPLEVEL_BINDING, options = {})
107
- @pry = Pry.new(options)
108
-
109
- if context
110
- target = Pry.binding_for(context)
111
- @pry.binding_stack << target
112
- @pry.inject_sticky_locals(target)
113
- end
114
-
115
- @pry.input_array << nil # TODO: shouldn't need this
116
- reset_output
117
- end
118
-
119
- def eval(*strs)
120
- reset_output
121
- result = nil
122
-
123
- strs.flatten.each do |str|
124
- str = "#{str.strip}\n"
125
- if @pry.process_command(str)
126
- result = last_command_result_or_output
127
- else
128
- result = @pry.evaluate_ruby(str)
129
- end
130
- end
131
-
132
- result
133
- end
134
-
135
- def context=(context)
136
- @pry.binding_stack << Pry.binding_for(context)
137
- end
138
-
139
- # TODO: eliminate duplication with Pry#repl
140
- def simulate_repl
141
- didnt_exit = nil
142
- break_data = nil
143
-
144
- didnt_exit = catch(:didnt_exit) do
145
- break_data = catch(:breakout) do
146
- yield self
147
- throw(:didnt_exit, true)
148
- end
149
- nil
150
- end
151
-
152
- raise "Failed to exit REPL" if didnt_exit
153
- break_data
154
- end
155
-
156
- def last_output
157
- @out.string if @out
158
- end
159
-
160
- def process_command(command_str, eval_str = '')
161
- @pry.process_command(command_str, eval_str) or raise "Not a valid command"
162
- last_command_result_or_output
163
- end
164
-
165
- protected
166
-
167
- def last_command_result
168
- result = Pry.current[:pry_cmd_result]
169
- result.retval if result
170
- end
171
-
172
- def last_command_result_or_output
173
- result = last_command_result
174
- if result != Pry::Command::VOID_VALUE
175
- result
176
- else
177
- last_output
178
- end
179
- end
180
-
181
- def reset_output
182
- @out = StringIO.new
183
- @pry.output = @out
184
- end
185
- end
data/man/pry.1 DELETED
@@ -1,195 +0,0 @@
1
- .\" generated with Ronn/v0.7.3
2
- .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
- .
4
- .TH "PRY" "1" "November 2011" "" ""
5
- .
6
- .SH "NAME"
7
- \fBPRY\fR \- A Reference to the PRY repl\.
8
- .
9
- .SH "Synopsis"
10
- \fBpry\fR [\fB\-\-version\fR] [\fB\-\-exec\fR] [\fB\-\-no\-pager\fR] [\fB\-\-no\-history\fR] [\fB\-\-no\-color\fR] [\fB\-f\fR] [\fB\-\-no\-plugins\fR] [\fB\-\-installed\-plugins\fR] [\fB\-\-simple\-prompt\fR] [\fB\-\-require\fR \fIfile\fR] [\fB\-I\fR] [\fB\-\-context\fR] [\fB\-\-help\fR]
11
- .
12
- .SH "DESCRIPTION"
13
- Pry is a powerful alternative to the standard IRB shell for Ruby\. It is written from scratch to provide a number of advanced features\.
14
- .
15
- .SH "HOMEPAGE"
16
- http://pry\.github\.com/
17
- .
18
- .SH "OPTIONS"
19
- .
20
- .TP
21
- \fB\-v \-\-version\fR
22
- Prints the version of Pry\.
23
- .
24
- .TP
25
- \fB\-e \-\-exec\fR
26
- Executes argument in context before the session starts\.
27
- .
28
- .TP
29
- \fB\-\-no\-pager\fR
30
- Disable pager for long output\.
31
- .
32
- .TP
33
- \fB\-\-no\-history\fR
34
- Disable history loading\.
35
- .
36
- .TP
37
- \fB\-\-no\-color\fR
38
- Disable syntax highlighting for session\.
39
- .
40
- .TP
41
- \fB\-f\fR
42
- Prevent loading of ~/\.pryrc for session\.
43
- .
44
- .TP
45
- \fB\-\-no\-plugins\fR
46
- Supress loading of plugins\.
47
- .
48
- .TP
49
- \fB\-\-installed\-plugins\fR
50
- List installed plugins\.
51
- .
52
- .TP
53
- \fB\-\-simple\-prompt\fR
54
- Enable simple prompt mode (eg, >>)\.
55
- .
56
- .TP
57
- \fB\-r \-\-require\fR
58
- Require a ruby script at startup\.
59
- .
60
- .TP
61
- \fB\-I\fR
62
- Add a path to the $LOAD_PATH
63
- .
64
- .TP
65
- \fB\-c \-\-context\fR
66
- Start the session in the specified context\. Equivalent to \fBcontext\.pry\fR in a session\.
67
- .
68
- .SH "FILES"
69
- ~/\.pryrc Personal pry initialization
70
- .
71
- .SH "EXAMPLES"
72
- .
73
- .SS "Basic Usage"
74
- .
75
- .nf
76
-
77
- $ pry
78
- [1] pry(main)>4 + 5
79
- => 9
80
- [2] pry(main)> def hello_world
81
- [2] pry(main)* puts "Hello, World!"
82
- [2] pry(main)* end
83
- => nil
84
- [3] pry(main)> hello_world
85
- Hello, World!
86
- => nil
87
- .
88
- .fi
89
- .
90
- .SS "Command Line Interaction"
91
- Prefix any command you want your shell to execute with a period and pry will return the results from your shell\.
92
- .
93
- .IP "" 4
94
- .
95
- .nf
96
-
97
- [1] pry(main)> \.date
98
- Fri Nov 11 09:52:07 EST 2011
99
- .
100
- .fi
101
- .
102
- .IP "" 0
103
- .
104
- .P
105
- On the command line enter \fBshell\-mode\fR to incorporate the current working directory into the Pry prompt\.
106
- .
107
- .IP "" 4
108
- .
109
- .nf
110
-
111
- pry(main)> shell\-mode
112
- pry main:/Users/john/ruby/projects/pry $ \.cd \.\.
113
- pry main:/Users/john/ruby/projects $ \.cd ~
114
- pry main:/Users/john $ \.pwd
115
- /Users/john
116
- pry main:/Users/john $ shell\-mode
117
- pry(main)>
118
- .
119
- .fi
120
- .
121
- .IP "" 0
122
- .
123
- .SS "State Navigation"
124
- The cd command is used to move into a new object (or scope) inside a Pry session\. When inside the new scope it becomes the self for the session and all commands and methods will operate on this new self\.
125
- .
126
- .IP "" 4
127
- .
128
- .nf
129
-
130
- pry(main)> self
131
- => main
132
- pry(main)> cd Pry
133
- pry(Pry):1> self
134
- => Pry
135
- pry(Pry):1> cd \.\.
136
- pry(main)>
137
- .
138
- .fi
139
- .
140
- .IP "" 0
141
- .
142
- .P
143
- The ls command is essentially a unified wrapper to a number of Ruby\'s introspection mechanisms, including (but not limited to) the following methods: methods, instance_variables, constants, local_variables, instance_methods, class_variables and all the various permutations thereof\.
144
- .
145
- .P
146
- By default typing ls will return a list of just the local and instance variables available in the current context\.
147
- .
148
- .IP "\(bu" 4
149
- The \-M option selects public instance methods (if available)\.
150
- .
151
- .IP "\(bu" 4
152
- The \-m option selects public methods\.
153
- .
154
- .IP "\(bu" 4
155
- The \-c option selects constants\.
156
- .
157
- .IP "\(bu" 4
158
- The \-i option select just instance variables\.
159
- .
160
- .IP "\(bu" 4
161
- The \-l option selects just local variables\.
162
- .
163
- .IP "\(bu" 4
164
- The \-s option modifies the \-c and \-m and \-M options to go up the superclass chain (excluding Object)\.
165
- .
166
- .IP "\(bu" 4
167
- The \-\-grep REGEX prunes the list to items that match the regex\.
168
- .
169
- .IP "" 0
170
- .
171
- .SS "Source Browsing"
172
- Simply typing show\-method method_name will pull the source for the method and display it with syntax highlighting\. You can also look up the source for multiple methods at the same time, by typing show\-method method1 method2\. As a convenience, Pry looks up both instance methods and class methods using this syntax, with priority given to instance methods\.
173
- .
174
- .IP "" 4
175
- .
176
- .nf
177
-
178
- pry(Pry):1> show\-method rep
179
-
180
- From: /Users/john/ruby/projects/pry/lib/pry/pry_instance\.rb @ line 191:
181
- Number of lines: 6
182
-
183
- def rep(target=TOPLEVEL_BINDING)
184
- target = Pry\.binding_for(target)
185
- result = re(target)
186
-
187
- show_result(result) if should_print?
188
- end
189
- .
190
- .fi
191
- .
192
- .IP "" 0
193
- .
194
- .SH "AUTHORS"
195
- Pry is primarily the work of John Mair (banisterfiend)