pry 0.11.3 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +346 -2
  3. data/LICENSE +1 -1
  4. data/README.md +351 -292
  5. data/bin/pry +1 -0
  6. data/lib/pry/basic_object.rb +8 -4
  7. data/lib/pry/block_command.rb +22 -0
  8. data/lib/pry/class_command.rb +194 -0
  9. data/lib/pry/cli.rb +58 -76
  10. data/lib/pry/code/code_file.rb +33 -28
  11. data/lib/pry/code/code_range.rb +7 -5
  12. data/lib/pry/code/loc.rb +26 -13
  13. data/lib/pry/code.rb +37 -33
  14. data/lib/pry/code_object.rb +41 -39
  15. data/lib/pry/color_printer.rb +47 -45
  16. data/lib/pry/command.rb +178 -374
  17. data/lib/pry/command_set.rb +89 -121
  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 +71 -59
  24. data/lib/pry/commands/cat/file_formatter.rb +55 -49
  25. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  26. data/lib/pry/commands/cat.rb +62 -54
  27. data/lib/pry/commands/cd.rb +40 -35
  28. data/lib/pry/commands/change_inspector.rb +29 -22
  29. data/lib/pry/commands/change_prompt.rb +48 -23
  30. data/lib/pry/commands/clear_screen.rb +20 -0
  31. data/lib/pry/commands/code_collector.rb +148 -133
  32. data/lib/pry/commands/disable_pry.rb +23 -19
  33. data/lib/pry/commands/easter_eggs.rb +19 -30
  34. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  35. data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
  36. data/lib/pry/commands/edit.rb +184 -160
  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 -16
  40. data/lib/pry/commands/find_method.rb +168 -162
  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 +151 -149
  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 +35 -28
  47. data/lib/pry/commands/ls/constants.rb +60 -43
  48. data/lib/pry/commands/ls/formatter.rb +42 -37
  49. data/lib/pry/commands/ls/globals.rb +38 -36
  50. data/lib/pry/commands/ls/grep.rb +17 -15
  51. data/lib/pry/commands/ls/instance_vars.rb +29 -28
  52. data/lib/pry/commands/ls/interrogatable.rb +18 -12
  53. data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
  54. data/lib/pry/commands/ls/local_names.rb +26 -24
  55. data/lib/pry/commands/ls/local_vars.rb +38 -30
  56. data/lib/pry/commands/ls/ls_entity.rb +47 -52
  57. data/lib/pry/commands/ls/methods.rb +49 -51
  58. data/lib/pry/commands/ls/methods_helper.rb +46 -42
  59. data/lib/pry/commands/ls/self_methods.rb +23 -23
  60. data/lib/pry/commands/ls.rb +124 -105
  61. data/lib/pry/commands/nesting.rb +21 -17
  62. data/lib/pry/commands/play.rb +92 -82
  63. data/lib/pry/commands/pry_backtrace.rb +22 -17
  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 +60 -48
  67. data/lib/pry/commands/reset.rb +16 -12
  68. data/lib/pry/commands/ri.rb +56 -45
  69. data/lib/pry/commands/save_file.rb +45 -43
  70. data/lib/pry/commands/shell_command.rb +52 -51
  71. data/lib/pry/commands/shell_mode.rb +22 -18
  72. data/lib/pry/commands/show_doc.rb +80 -70
  73. data/lib/pry/commands/show_info.rb +192 -167
  74. data/lib/pry/commands/show_input.rb +16 -11
  75. data/lib/pry/commands/show_source.rb +110 -42
  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 +20 -16
  79. data/lib/pry/commands/watch_expression/expression.rb +32 -27
  80. data/lib/pry/commands/watch_expression.rb +89 -84
  81. data/lib/pry/commands/whereami.rb +156 -148
  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 +312 -9
  88. data/lib/pry/control_d_handler.rb +28 -0
  89. data/lib/pry/core_extensions.rb +13 -10
  90. data/lib/pry/editor.rb +56 -34
  91. data/lib/pry/env.rb +18 -0
  92. data/lib/pry/exception_handler.rb +43 -0
  93. data/lib/pry/exceptions.rb +13 -18
  94. data/lib/pry/forwardable.rb +5 -1
  95. data/lib/pry/helpers/base_helpers.rb +58 -58
  96. data/lib/pry/helpers/command_helpers.rb +52 -62
  97. data/lib/pry/helpers/documentation_helpers.rb +21 -13
  98. data/lib/pry/helpers/options_helpers.rb +14 -7
  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 +20 -18
  102. data/lib/pry/helpers.rb +3 -0
  103. data/lib/pry/history.rb +65 -60
  104. data/lib/pry/hooks.rb +24 -15
  105. data/lib/pry/indent.rb +72 -70
  106. data/lib/pry/input_completer.rb +251 -228
  107. data/lib/pry/input_lock.rb +7 -10
  108. data/lib/pry/inspector.rb +36 -24
  109. data/lib/pry/last_exception.rb +45 -45
  110. data/lib/pry/method/disowned.rb +18 -5
  111. data/lib/pry/method/patcher.rb +14 -5
  112. data/lib/pry/method/weird_method_locator.rb +74 -51
  113. data/lib/pry/method.rb +175 -121
  114. data/lib/pry/object_path.rb +37 -28
  115. data/lib/pry/output.rb +122 -35
  116. data/lib/pry/pager.rb +187 -180
  117. data/lib/pry/prompt.rb +213 -25
  118. data/lib/pry/pry_class.rb +91 -96
  119. data/lib/pry/pry_instance.rb +258 -223
  120. data/lib/pry/repl.rb +49 -25
  121. data/lib/pry/repl_file_loader.rb +27 -22
  122. data/lib/pry/ring.rb +89 -0
  123. data/lib/pry/slop/commands.rb +164 -170
  124. data/lib/pry/slop/option.rb +172 -170
  125. data/lib/pry/slop.rb +567 -556
  126. data/lib/pry/syntax_highlighter.rb +26 -0
  127. data/lib/pry/system_command_handler.rb +17 -0
  128. data/lib/pry/testable/evalable.rb +21 -12
  129. data/lib/pry/testable/mockable.rb +18 -10
  130. data/lib/pry/testable/pry_tester.rb +71 -56
  131. data/lib/pry/testable/utility.rb +29 -21
  132. data/lib/pry/testable/variables.rb +49 -43
  133. data/lib/pry/testable.rb +59 -61
  134. data/lib/pry/version.rb +3 -1
  135. data/lib/pry/warning.rb +20 -0
  136. data/lib/pry/wrapped_module/candidate.rb +31 -23
  137. data/lib/pry/wrapped_module.rb +63 -59
  138. data/lib/pry.rb +132 -149
  139. metadata +39 -51
  140. data/lib/pry/commands/disabled_commands.rb +0 -2
  141. data/lib/pry/commands/gem_cd.rb +0 -26
  142. data/lib/pry/commands/gem_install.rb +0 -32
  143. data/lib/pry/commands/gem_list.rb +0 -33
  144. data/lib/pry/commands/gem_open.rb +0 -29
  145. data/lib/pry/commands/gem_readme.rb +0 -25
  146. data/lib/pry/commands/gem_search.rb +0 -40
  147. data/lib/pry/commands/gist.rb +0 -101
  148. data/lib/pry/commands/install_command.rb +0 -53
  149. data/lib/pry/commands/list_prompts.rb +0 -35
  150. data/lib/pry/commands/simple_prompt.rb +0 -22
  151. data/lib/pry/commands.rb +0 -6
  152. data/lib/pry/config/behavior.rb +0 -231
  153. data/lib/pry/config/convenience.rb +0 -25
  154. data/lib/pry/config/default.rb +0 -149
  155. data/lib/pry/config/memoization.rb +0 -44
  156. data/lib/pry/history_array.rb +0 -121
  157. data/lib/pry/platform.rb +0 -93
  158. data/lib/pry/plugins.rb +0 -118
  159. data/lib/pry/rbx_path.rb +0 -22
  160. data/lib/pry/rubygem.rb +0 -84
  161. data/lib/pry/terminal.rb +0 -90
data/lib/pry/plugins.rb DELETED
@@ -1,118 +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.exist?(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('-', '_')}=", Pry::Config.from_hash({}))
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
-
64
- def supported?
65
- pry_version = Gem::Version.new(VERSION)
66
- spec.dependencies.each do |dependency|
67
- if dependency.name == "pry"
68
- return dependency.requirement.satisfied_by?(pry_version)
69
- end
70
- end
71
- true
72
- end
73
- end
74
-
75
- def initialize
76
- @plugins = []
77
- end
78
-
79
- # Find all installed Pry plugins and store them in an internal array.
80
- def locate_plugins
81
- gem_list.each do |gem|
82
- next if gem.name !~ PRY_PLUGIN_PREFIX
83
- plugin_name = gem.name.split('-', 2).last
84
- plugin = Plugin.new(plugin_name, gem.name, gem, false)
85
- @plugins << plugin.tap(&:enable!) if plugin.supported? && !plugin_located?(plugin)
86
- end
87
- @plugins
88
- end
89
-
90
- # @return [Hash] A hash with all plugin names (minus the 'pry-') as
91
- # keys and Plugin objects as values.
92
- def plugins
93
- h = Hash.new { |_, key| NoPlugin.new(key) }
94
- @plugins.each do |plugin|
95
- h[plugin.name] = plugin
96
- end
97
- h
98
- end
99
-
100
- # Require all enabled plugins, disabled plugins are skipped.
101
- def load_plugins
102
- @plugins.each do |plugin|
103
- plugin.activate! if plugin.enabled?
104
- end
105
- end
106
-
107
- private
108
- def plugin_located?(plugin)
109
- @plugins.any? { |existing| existing.gem_name == plugin.gem_name }
110
- end
111
-
112
- def gem_list
113
- Gem.refresh
114
- Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')
115
- end
116
- end
117
-
118
- 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
- Pry::Helpers::BaseHelpers.rbx? && (path.start_with?("kernel") || path.start_with?("lib")) && File.exist?(convert_path_to_full(path))
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,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 #{ Pry::Helpers::Text.green(name) }."
75
- rescue Gem::GemNotFoundException
76
- raise CommandError,
77
- "Gem #{ Pry::Helpers::Text.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,90 +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::BaseHelpers.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
- size = [$2, $1]
81
- size if nonzero_column?(size)
82
- end
83
-
84
- private
85
-
86
- def nonzero_column?(size)
87
- size[1].to_i > 0
88
- end
89
- end
90
- end