pry 0.12.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +162 -1
  3. data/LICENSE +1 -1
  4. data/README.md +331 -269
  5. data/bin/pry +5 -0
  6. data/lib/pry.rb +132 -119
  7. data/lib/pry/basic_object.rb +8 -4
  8. data/lib/pry/block_command.rb +22 -0
  9. data/lib/pry/class_command.rb +194 -0
  10. data/lib/pry/cli.rb +43 -51
  11. data/lib/pry/code.rb +40 -28
  12. data/lib/pry/code/code_file.rb +28 -24
  13. data/lib/pry/code/code_range.rb +4 -2
  14. data/lib/pry/code/loc.rb +15 -8
  15. data/lib/pry/code_object.rb +40 -38
  16. data/lib/pry/color_printer.rb +47 -46
  17. data/lib/pry/command.rb +166 -369
  18. data/lib/pry/command_set.rb +76 -73
  19. data/lib/pry/command_state.rb +31 -0
  20. data/lib/pry/commands/amend_line.rb +86 -81
  21. data/lib/pry/commands/bang.rb +18 -14
  22. data/lib/pry/commands/bang_pry.rb +15 -11
  23. data/lib/pry/commands/cat.rb +61 -54
  24. data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
  25. data/lib/pry/commands/cat/exception_formatter.rb +71 -60
  26. data/lib/pry/commands/cat/file_formatter.rb +55 -49
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  28. data/lib/pry/commands/cd.rb +40 -35
  29. data/lib/pry/commands/change_inspector.rb +29 -22
  30. data/lib/pry/commands/change_prompt.rb +44 -39
  31. data/lib/pry/commands/clear_screen.rb +16 -10
  32. data/lib/pry/commands/code_collector.rb +148 -133
  33. data/lib/pry/commands/disable_pry.rb +23 -19
  34. data/lib/pry/commands/easter_eggs.rb +19 -30
  35. data/lib/pry/commands/edit.rb +184 -161
  36. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  37. data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
  38. data/lib/pry/commands/exit.rb +39 -35
  39. data/lib/pry/commands/exit_all.rb +24 -20
  40. data/lib/pry/commands/exit_program.rb +20 -16
  41. data/lib/pry/commands/find_method.rb +168 -160
  42. data/lib/pry/commands/fix_indent.rb +16 -12
  43. data/lib/pry/commands/help.rb +140 -133
  44. data/lib/pry/commands/hist.rb +151 -150
  45. data/lib/pry/commands/import_set.rb +20 -16
  46. data/lib/pry/commands/jump_to.rb +25 -21
  47. data/lib/pry/commands/list_inspectors.rb +35 -28
  48. data/lib/pry/commands/ls.rb +124 -102
  49. data/lib/pry/commands/ls/constants.rb +59 -42
  50. data/lib/pry/commands/ls/formatter.rb +50 -46
  51. data/lib/pry/commands/ls/globals.rb +38 -34
  52. data/lib/pry/commands/ls/grep.rb +17 -13
  53. data/lib/pry/commands/ls/instance_vars.rb +29 -27
  54. data/lib/pry/commands/ls/interrogatable.rb +18 -12
  55. data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
  56. data/lib/pry/commands/ls/local_names.rb +26 -22
  57. data/lib/pry/commands/ls/local_vars.rb +38 -28
  58. data/lib/pry/commands/ls/ls_entity.rb +47 -51
  59. data/lib/pry/commands/ls/methods.rb +44 -43
  60. data/lib/pry/commands/ls/methods_helper.rb +46 -42
  61. data/lib/pry/commands/ls/self_methods.rb +23 -22
  62. data/lib/pry/commands/nesting.rb +21 -17
  63. data/lib/pry/commands/play.rb +93 -82
  64. data/lib/pry/commands/pry_backtrace.rb +22 -17
  65. data/lib/pry/commands/pry_version.rb +15 -11
  66. data/lib/pry/commands/raise_up.rb +27 -22
  67. data/lib/pry/commands/reload_code.rb +60 -48
  68. data/lib/pry/commands/reset.rb +16 -12
  69. data/lib/pry/commands/ri.rb +55 -45
  70. data/lib/pry/commands/save_file.rb +45 -43
  71. data/lib/pry/commands/shell_command.rb +51 -51
  72. data/lib/pry/commands/shell_mode.rb +21 -17
  73. data/lib/pry/commands/show_doc.rb +80 -68
  74. data/lib/pry/commands/show_info.rb +189 -171
  75. data/lib/pry/commands/show_input.rb +16 -11
  76. data/lib/pry/commands/show_source.rb +110 -45
  77. data/lib/pry/commands/stat.rb +35 -31
  78. data/lib/pry/commands/switch_to.rb +21 -15
  79. data/lib/pry/commands/toggle_color.rb +20 -16
  80. data/lib/pry/commands/watch_expression.rb +89 -86
  81. data/lib/pry/commands/watch_expression/expression.rb +32 -27
  82. data/lib/pry/commands/whereami.rb +156 -148
  83. data/lib/pry/commands/wtf.rb +75 -50
  84. data/lib/pry/config.rb +307 -25
  85. data/lib/pry/config/attributable.rb +22 -0
  86. data/lib/pry/config/lazy_value.rb +29 -0
  87. data/lib/pry/config/memoized_value.rb +34 -0
  88. data/lib/pry/config/value.rb +24 -0
  89. data/lib/pry/control_d_handler.rb +28 -0
  90. data/lib/pry/core_extensions.rb +9 -7
  91. data/lib/pry/editor.rb +48 -21
  92. data/lib/pry/env.rb +18 -0
  93. data/lib/pry/exception_handler.rb +43 -0
  94. data/lib/pry/exceptions.rb +13 -16
  95. data/lib/pry/forwardable.rb +5 -1
  96. data/lib/pry/helpers.rb +2 -0
  97. data/lib/pry/helpers/base_helpers.rb +68 -197
  98. data/lib/pry/helpers/command_helpers.rb +50 -61
  99. data/lib/pry/helpers/documentation_helpers.rb +20 -13
  100. data/lib/pry/helpers/options_helpers.rb +14 -7
  101. data/lib/pry/helpers/platform.rb +7 -5
  102. data/lib/pry/helpers/table.rb +33 -26
  103. data/lib/pry/helpers/text.rb +17 -14
  104. data/lib/pry/history.rb +48 -56
  105. data/lib/pry/hooks.rb +21 -12
  106. data/lib/pry/indent.rb +54 -50
  107. data/lib/pry/input_completer.rb +248 -230
  108. data/lib/pry/input_lock.rb +8 -9
  109. data/lib/pry/inspector.rb +36 -24
  110. data/lib/pry/last_exception.rb +45 -45
  111. data/lib/pry/method.rb +141 -94
  112. data/lib/pry/method/disowned.rb +16 -4
  113. data/lib/pry/method/patcher.rb +12 -3
  114. data/lib/pry/method/weird_method_locator.rb +68 -44
  115. data/lib/pry/object_path.rb +33 -25
  116. data/lib/pry/output.rb +121 -35
  117. data/lib/pry/pager.rb +186 -180
  118. data/lib/pry/prompt.rb +123 -54
  119. data/lib/pry/pry_class.rb +61 -103
  120. data/lib/pry/pry_instance.rb +217 -215
  121. data/lib/pry/repl.rb +18 -22
  122. data/lib/pry/repl_file_loader.rb +27 -21
  123. data/lib/pry/ring.rb +11 -6
  124. data/lib/pry/slop.rb +574 -563
  125. data/lib/pry/slop/commands.rb +164 -169
  126. data/lib/pry/slop/option.rb +172 -168
  127. data/lib/pry/syntax_highlighter.rb +26 -0
  128. data/lib/pry/system_command_handler.rb +17 -0
  129. data/lib/pry/testable.rb +59 -61
  130. data/lib/pry/testable/evalable.rb +21 -12
  131. data/lib/pry/testable/mockable.rb +18 -10
  132. data/lib/pry/testable/pry_tester.rb +71 -56
  133. data/lib/pry/testable/utility.rb +29 -21
  134. data/lib/pry/testable/variables.rb +49 -43
  135. data/lib/pry/version.rb +3 -1
  136. data/lib/pry/warning.rb +27 -0
  137. data/lib/pry/wrapped_module.rb +51 -42
  138. data/lib/pry/wrapped_module/candidate.rb +21 -14
  139. metadata +35 -35
  140. data/lib/pry/commands.rb +0 -6
  141. data/lib/pry/commands/disabled_commands.rb +0 -2
  142. data/lib/pry/commands/gem_cd.rb +0 -26
  143. data/lib/pry/commands/gem_install.rb +0 -32
  144. data/lib/pry/commands/gem_list.rb +0 -33
  145. data/lib/pry/commands/gem_open.rb +0 -29
  146. data/lib/pry/commands/gem_readme.rb +0 -25
  147. data/lib/pry/commands/gem_search.rb +0 -40
  148. data/lib/pry/commands/gem_stats.rb +0 -83
  149. data/lib/pry/commands/gist.rb +0 -102
  150. data/lib/pry/commands/install_command.rb +0 -54
  151. data/lib/pry/config/behavior.rb +0 -255
  152. data/lib/pry/config/convenience.rb +0 -28
  153. data/lib/pry/config/default.rb +0 -159
  154. data/lib/pry/config/memoization.rb +0 -48
  155. data/lib/pry/platform.rb +0 -91
  156. data/lib/pry/plugins.rb +0 -122
  157. data/lib/pry/rubygem.rb +0 -84
  158. data/lib/pry/terminal.rb +0 -91
data/lib/pry/platform.rb DELETED
@@ -1,91 +0,0 @@
1
- class Pry
2
- module Platform
3
- extend self
4
-
5
- #
6
- # @return [Boolean]
7
- # Returns true if Pry is running on Mac OSX.
8
- #
9
- # @note
10
- # Queries RbConfig::CONFIG['host_os'] with a best guess.
11
- #
12
- def mac_osx?
13
- !!(RbConfig::CONFIG['host_os'] =~ /\Adarwin/i)
14
- end
15
-
16
- #
17
- # @return [Boolean]
18
- # Returns true if Pry is running on Linux.
19
- #
20
- # @note
21
- # Queries RbConfig::CONFIG['host_os'] with a best guess.
22
- #
23
- def linux?
24
- !!(RbConfig::CONFIG['host_os'] =~ /linux/i)
25
- end
26
-
27
- #
28
- # @return [Boolean]
29
- # Returns true if Pry is running on Windows.
30
- #
31
- # @note
32
- # Queries RbConfig::CONFIG['host_os'] with a best guess.
33
- #
34
- def windows?
35
- !!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
36
- end
37
-
38
- #
39
- # @return [Boolean]
40
- # Returns true when Pry is running on Windows with ANSI support.
41
- #
42
- def windows_ansi?
43
- return false if not windows?
44
-
45
- !!(defined?(Win32::Console) or ENV['ANSICON'] or mri_2?)
46
- end
47
-
48
- #
49
- # @return [Boolean]
50
- # Returns true when Pry is being run from JRuby.
51
- #
52
- def jruby?
53
- RbConfig::CONFIG['ruby_install_name'] == 'jruby'
54
- end
55
-
56
- #
57
- # @return [Boolean]
58
- # Returns true when Pry is being run from JRuby in 1.9 mode.
59
- #
60
- def jruby_19?
61
- jruby? and RbConfig::CONFIG['ruby_version'] == '1.9'
62
- end
63
-
64
- #
65
- # @return [Boolean]
66
- # Returns true when Pry is being run from MRI (CRuby).
67
- #
68
- def mri?
69
- RbConfig::CONFIG['ruby_install_name'] == 'ruby'
70
- end
71
-
72
- #
73
- # @return [Boolean]
74
- # Returns true when Pry is being run from MRI v1.9+ (CRuby).
75
- #
76
- def mri_19?
77
- !!(mri? and RUBY_VERSION =~ /\A1\.9/)
78
- end
79
-
80
- #
81
- # @return [Boolean]
82
- # Returns true when Pry is being run from MRI v2+ (CRuby).
83
- #
84
- def mri_2?
85
- !!(mri? and RUBY_VERSION =~ /\A2/)
86
- end
87
- end
88
-
89
- # Not supported on MRI 2.2 and lower.
90
- deprecate_constant(:Platform) if respond_to?(:deprecate_constant)
91
- end
data/lib/pry/plugins.rb DELETED
@@ -1,122 +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
- return unless File.exist?(cli_options_file)
39
-
40
- cli_options_file = File.realpath(cli_options_file) if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.4.4")
41
- require cli_options_file
42
- end
43
-
44
- # Activate the plugin (require the gem - enables/loads the
45
- # plugin immediately at point of call, even if plugin is
46
- # disabled)
47
- # Does not reload plugin if it's already active.
48
- def activate!
49
- # Create the configuration object for the plugin.
50
- Pry.config.send("#{gem_name.gsub('-', '_')}=", Pry::Config.from_hash({}))
51
-
52
- begin
53
- require gem_name if !active?
54
- rescue LoadError => e
55
- warn "Found plugin #{gem_name}, but could not require '#{gem_name}'"
56
- warn e
57
- rescue => e
58
- warn "require '#{gem_name}' # Failed, saying: #{e}"
59
- end
60
-
61
- self.active = true
62
- self.enabled = true
63
- end
64
-
65
- alias active? active
66
- alias enabled? enabled
67
-
68
- def supported?
69
- pry_version = Gem::Version.new(VERSION)
70
- spec.dependencies.each do |dependency|
71
- if dependency.name == "pry"
72
- return dependency.requirement.satisfied_by?(pry_version)
73
- end
74
- end
75
- true
76
- end
77
- end
78
-
79
- def initialize
80
- @plugins = []
81
- end
82
-
83
- # Find all installed Pry plugins and store them in an internal array.
84
- def locate_plugins
85
- gem_list.each do |gem|
86
- next if gem.name !~ PRY_PLUGIN_PREFIX
87
-
88
- plugin_name = gem.name.split('-', 2).last
89
- plugin = Plugin.new(plugin_name, gem.name, gem, false)
90
- @plugins << plugin.tap(&:enable!) if plugin.supported? && !plugin_located?(plugin)
91
- end
92
- @plugins
93
- end
94
-
95
- # @return [Hash] A hash with all plugin names (minus the 'pry-') as
96
- # keys and Plugin objects as values.
97
- def plugins
98
- h = Hash.new { |_, key| NoPlugin.new(key) }
99
- @plugins.each do |plugin|
100
- h[plugin.name] = plugin
101
- end
102
- h
103
- end
104
-
105
- # Require all enabled plugins, disabled plugins are skipped.
106
- def load_plugins
107
- @plugins.each do |plugin|
108
- plugin.activate! if plugin.enabled?
109
- end
110
- end
111
-
112
- private
113
- def plugin_located?(plugin)
114
- @plugins.any? { |existing| existing.gem_name == plugin.gem_name }
115
- end
116
-
117
- def gem_list
118
- Gem.refresh
119
- Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')
120
- end
121
- end
122
- end
data/lib/pry/rubygem.rb DELETED
@@ -1,84 +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
- first_spec = specs.sort_by { |spec| Gem::Version.new(spec.version) }.last
27
-
28
- first_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
- require 'rubygems/dependency_installer'
61
- gem_config = Gem.configuration['gem']
62
- gemrc_opts = (gem_config.nil? ? "" : gem_config.split(' '))
63
- destination = if gemrc_opts.include?('--user-install')
64
- Gem.user_dir
65
- elsif File.writable?(Gem.dir)
66
- Gem.dir
67
- else
68
- Gem.user_dir
69
- end
70
- installer = Gem::DependencyInstaller.new(install_dir: destination)
71
- installer.install(name)
72
- rescue Errno::EACCES
73
- raise CommandError,
74
- "Insufficient permissions to install #{green(name)}."
75
- rescue Gem::GemNotFoundException
76
- raise CommandError,
77
- "Gem #{green(name)} not found. Aborting installation."
78
- else
79
- Gem.refresh
80
- end
81
- end
82
-
83
- end
84
- end
data/lib/pry/terminal.rb DELETED
@@ -1,91 +0,0 @@
1
- # coding: utf-8
2
- class Pry::Terminal
3
- class << self
4
- # Return a pair of [rows, columns] which gives the size of the window.
5
- #
6
- # If the window size cannot be determined, return nil.
7
- def screen_size
8
- rows, cols = actual_screen_size
9
- if rows.to_i != 0 && cols.to_i != 0
10
- [rows.to_i, cols.to_i]
11
- else
12
- nil
13
- end
14
- end
15
-
16
- # Return a screen size or a default if that fails.
17
- def size! default = [27, 80]
18
- screen_size || default
19
- end
20
-
21
- # Return a screen width or the default if that fails.
22
- def width!
23
- size![1]
24
- end
25
-
26
- # Return a screen height or the default if that fails.
27
- def height!
28
- size![0]
29
- end
30
-
31
- def actual_screen_size
32
- # The best way, if possible (requires non-jruby ≥1.9 or io-console gem)
33
- screen_size_according_to_io_console or
34
- # Fall back to the old standby, though it might be stale:
35
- screen_size_according_to_env or
36
- # Fall further back, though this one is also out of date without something
37
- # calling Readline.set_screen_size
38
- screen_size_according_to_readline or
39
- # Windows users can otherwise run ansicon and get a decent answer:
40
- screen_size_according_to_ansicon_env
41
- end
42
-
43
- def screen_size_according_to_io_console
44
- return if Pry::Helpers::Platform.jruby?
45
-
46
- begin
47
- require 'io/console'
48
-
49
- begin
50
- if $stdout.respond_to?(:tty?) && $stdout.tty? && $stdout.respond_to?(:winsize)
51
- $stdout.winsize
52
- end
53
- rescue Errno::EOPNOTSUPP
54
- # $stdout is probably a socket, which doesn't support #winsize.
55
- end
56
- rescue LoadError
57
- # They probably don't have the io/console stdlib or the io-console gem.
58
- # We'll keep trying.
59
- end
60
- end
61
-
62
- def screen_size_according_to_env
63
- size = [ENV['LINES'] || ENV['ROWS'], ENV['COLUMNS']]
64
- size if nonzero_column?(size)
65
- end
66
-
67
- def screen_size_according_to_readline
68
- if defined?(Readline) && Readline.respond_to?(:get_screen_size)
69
- size = Readline.get_screen_size
70
- size if nonzero_column?(size)
71
- end
72
- rescue Java::JavaLang::NullPointerException
73
- # This rescue won't happen on jrubies later than:
74
- # https://github.com/jruby/jruby/pull/436
75
- nil
76
- end
77
-
78
- def screen_size_according_to_ansicon_env
79
- return unless ENV['ANSICON'] =~ /\((.*)x(.*)\)/
80
-
81
- size = [$2, $1]
82
- size if nonzero_column?(size)
83
- end
84
-
85
- private
86
-
87
- def nonzero_column?(size)
88
- size[1].to_i > 0
89
- end
90
- end
91
- end