pry 0.11.3 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +157 -1
  3. data/LICENSE +1 -1
  4. data/README.md +13 -30
  5. data/bin/pry +0 -4
  6. data/lib/pry/cli.rb +17 -24
  7. data/lib/pry/code/code_file.rb +5 -4
  8. data/lib/pry/code/code_range.rb +3 -3
  9. data/lib/pry/code/loc.rb +14 -8
  10. data/lib/pry/code.rb +6 -6
  11. data/lib/pry/code_object.rb +4 -4
  12. data/lib/pry/color_printer.rb +1 -0
  13. data/lib/pry/command.rb +36 -29
  14. data/lib/pry/command_set.rb +17 -52
  15. data/lib/pry/commands/amend_line.rb +3 -4
  16. data/lib/pry/commands/bang.rb +1 -1
  17. data/lib/pry/commands/cat/exception_formatter.rb +9 -8
  18. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  19. data/lib/pry/commands/cat.rb +7 -6
  20. data/lib/pry/commands/change_prompt.rb +29 -9
  21. data/lib/pry/commands/clear_screen.rb +14 -0
  22. data/lib/pry/commands/code_collector.rb +9 -9
  23. data/lib/pry/commands/easter_eggs.rb +3 -3
  24. data/lib/pry/commands/edit.rb +8 -7
  25. data/lib/pry/commands/exit.rb +2 -1
  26. data/lib/pry/commands/find_method.rb +11 -13
  27. data/lib/pry/commands/gem_cd.rb +1 -1
  28. data/lib/pry/commands/gem_install.rb +2 -2
  29. data/lib/pry/commands/gem_list.rb +2 -2
  30. data/lib/pry/commands/gem_open.rb +1 -1
  31. data/lib/pry/commands/gem_search.rb +2 -2
  32. data/lib/pry/commands/gem_stats.rb +83 -0
  33. data/lib/pry/commands/gist.rb +7 -6
  34. data/lib/pry/commands/help.rb +3 -3
  35. data/lib/pry/commands/hist.rb +9 -8
  36. data/lib/pry/commands/import_set.rb +2 -1
  37. data/lib/pry/commands/install_command.rb +7 -6
  38. data/lib/pry/commands/list_inspectors.rb +2 -2
  39. data/lib/pry/commands/ls/constants.rb +4 -4
  40. data/lib/pry/commands/ls/formatter.rb +3 -2
  41. data/lib/pry/commands/ls/globals.rb +0 -2
  42. data/lib/pry/commands/ls/grep.rb +0 -2
  43. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  44. data/lib/pry/commands/ls/local_names.rb +0 -2
  45. data/lib/pry/commands/ls/local_vars.rb +0 -2
  46. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  47. data/lib/pry/commands/ls/methods.rb +0 -3
  48. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  49. data/lib/pry/commands/ls/self_methods.rb +0 -1
  50. data/lib/pry/commands/ls.rb +27 -30
  51. data/lib/pry/commands/play.rb +1 -2
  52. data/lib/pry/commands/pry_backtrace.rb +1 -1
  53. data/lib/pry/commands/raise_up.rb +2 -1
  54. data/lib/pry/commands/ri.rb +5 -4
  55. data/lib/pry/commands/shell_command.rb +3 -2
  56. data/lib/pry/commands/shell_mode.rb +6 -6
  57. data/lib/pry/commands/show_doc.rb +5 -7
  58. data/lib/pry/commands/show_info.rb +25 -18
  59. data/lib/pry/commands/show_source.rb +5 -2
  60. data/lib/pry/commands/stat.rb +1 -1
  61. data/lib/pry/commands/watch_expression.rb +9 -7
  62. data/lib/pry/commands/whereami.rb +4 -4
  63. data/lib/pry/commands/wtf.rb +15 -2
  64. data/lib/pry/config/behavior.rb +229 -205
  65. data/lib/pry/config/convenience.rb +24 -21
  66. data/lib/pry/config/default.rb +153 -143
  67. data/lib/pry/config/memoization.rb +41 -37
  68. data/lib/pry/config.rb +33 -9
  69. data/lib/pry/core_extensions.rb +4 -3
  70. data/lib/pry/editor.rb +5 -12
  71. data/lib/pry/exceptions.rb +0 -2
  72. data/lib/pry/helpers/base_helpers.rb +133 -4
  73. data/lib/pry/helpers/command_helpers.rb +5 -4
  74. data/lib/pry/helpers/documentation_helpers.rb +2 -2
  75. data/lib/pry/helpers/options_helpers.rb +5 -5
  76. data/lib/pry/helpers/platform.rb +58 -0
  77. data/lib/pry/helpers/table.rb +20 -15
  78. data/lib/pry/helpers/text.rb +3 -4
  79. data/lib/pry/helpers.rb +1 -0
  80. data/lib/pry/history.rb +21 -8
  81. data/lib/pry/hooks.rb +3 -3
  82. data/lib/pry/indent.rb +15 -17
  83. data/lib/pry/input_completer.rb +12 -7
  84. data/lib/pry/input_lock.rb +0 -2
  85. data/lib/pry/last_exception.rb +1 -1
  86. data/lib/pry/method/disowned.rb +2 -1
  87. data/lib/pry/method/patcher.rb +2 -2
  88. data/lib/pry/method/weird_method_locator.rb +7 -8
  89. data/lib/pry/method.rb +37 -31
  90. data/lib/pry/object_path.rb +5 -4
  91. data/lib/pry/output.rb +3 -2
  92. data/lib/pry/pager.rb +194 -186
  93. data/lib/pry/platform.rb +79 -81
  94. data/lib/pry/plugins.rb +7 -3
  95. data/lib/pry/prompt.rb +144 -25
  96. data/lib/pry/pry_class.rb +53 -29
  97. data/lib/pry/pry_instance.rb +88 -55
  98. data/lib/pry/repl.rb +33 -4
  99. data/lib/pry/repl_file_loader.rb +1 -2
  100. data/lib/pry/ring.rb +84 -0
  101. data/lib/pry/rubygem.rb +6 -6
  102. data/lib/pry/slop/commands.rb +3 -4
  103. data/lib/pry/slop/option.rb +19 -21
  104. data/lib/pry/slop.rb +17 -17
  105. data/lib/pry/terminal.rb +2 -1
  106. data/lib/pry/testable/mockable.rb +2 -2
  107. data/lib/pry/testable/pry_tester.rb +1 -1
  108. data/lib/pry/testable/utility.rb +2 -2
  109. data/lib/pry/testable/variables.rb +1 -1
  110. data/lib/pry/version.rb +1 -1
  111. data/lib/pry/wrapped_module/candidate.rb +2 -2
  112. data/lib/pry/wrapped_module.rb +15 -15
  113. data/lib/pry.rb +17 -47
  114. metadata +8 -20
  115. data/lib/pry/commands/list_prompts.rb +0 -35
  116. data/lib/pry/commands/simple_prompt.rb +0 -22
  117. data/lib/pry/history_array.rb +0 -121
  118. data/lib/pry/rbx_path.rb +0 -22
data/lib/pry.rb CHANGED
@@ -1,6 +1,3 @@
1
- # (C) John Mair (banisterfiend) 2016
2
- # MIT License
3
- #
4
1
  require 'pp'
5
2
  require 'pry/forwardable'
6
3
  require 'pry/input_lock'
@@ -13,6 +10,7 @@ class Pry
13
10
  # The default hooks - display messages when beginning and ending Pry sessions.
14
11
  DEFAULT_HOOKS = Pry::Hooks.new.add_hook(:before_session, :default) do |out, target, _pry_|
15
12
  next if _pry_.quiet?
13
+
16
14
  _pry_.run_command("whereami --quiet")
17
15
  end
18
16
 
@@ -46,47 +44,18 @@ class Pry
46
44
  else
47
45
  output.puts "#{exception.class}: #{exception.message}"
48
46
  output.puts "from #{exception.backtrace.first}"
47
+
48
+ if exception.respond_to? :cause
49
+ cause = exception.cause
50
+ while cause
51
+ output.puts "Caused by #{cause.class}: #{cause}\n"
52
+ output.puts "from #{cause.backtrace.first}"
53
+ cause = cause.cause
54
+ end
55
+ end
49
56
  end
50
57
  end
51
58
 
52
- DEFAULT_PROMPT_NAME = 'pry'
53
-
54
- # The default prompt; includes the target and nesting level
55
- DEFAULT_PROMPT = [
56
- proc { |target_self, nest_level, pry|
57
- "[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}> "
58
- },
59
-
60
- proc { |target_self, nest_level, pry|
61
- "[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}* "
62
- }
63
- ]
64
-
65
- DEFAULT_PROMPT_SAFE_OBJECTS = [String, Numeric, Symbol, nil, true, false]
66
-
67
- # A simple prompt - doesn't display target or nesting level
68
- SIMPLE_PROMPT = [proc { ">> " }, proc { " | " }]
69
-
70
- NO_PROMPT = [proc { '' }, proc { '' }]
71
-
72
- SHELL_PROMPT = [
73
- proc { |target_self, _, _pry_| "#{_pry_.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " },
74
- proc { |target_self, _, _pry_| "#{_pry_.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} * " }
75
- ]
76
-
77
- # A prompt that includes the full object path as well as
78
- # input/output (_in_ and _out_) information. Good for navigation.
79
- NAV_PROMPT = [
80
- proc do |_, _, _pry_|
81
- tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
82
- "[#{_pry_.input_array.count}] (#{_pry_.config.prompt_name}) #{tree}: #{_pry_.binding_stack.size - 1}> "
83
- end,
84
- proc do |_, _, _pry_|
85
- tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
86
- "[#{_pry_.input_array.count}] (#{ _pry_.config.prompt_name}) #{tree}: #{_pry_.binding_stack.size - 1}* "
87
- end,
88
- ]
89
-
90
59
  # Deal with the ^D key being pressed. Different behaviour in different cases:
91
60
  # 1. In an expression behave like `!` command.
92
61
  # 2. At top-level session behave like `exit` command.
@@ -112,10 +81,6 @@ class Pry
112
81
  end
113
82
  end
114
83
 
115
- # Store the current working directory. This allows show-source etc. to work if
116
- # your process has changed directory since boot. [Issue #675]
117
- INITIAL_PWD = Dir.pwd
118
-
119
84
  # This is to keep from breaking under Rails 3.2 for people who are doing that
120
85
  # IRB = Pry thing.
121
86
  module ExtendCommandBundle; end
@@ -133,9 +98,8 @@ require 'pathname'
133
98
 
134
99
  require 'pry/version'
135
100
  require 'pry/repl'
136
- require 'pry/rbx_path'
137
101
  require 'pry/code'
138
- require 'pry/history_array'
102
+ require 'pry/ring'
139
103
  require 'pry/helpers'
140
104
  require 'pry/code_object'
141
105
  require 'pry/method'
@@ -146,6 +110,12 @@ require 'pry/command_set'
146
110
  require 'pry/commands'
147
111
  require 'pry/plugins'
148
112
  require 'pry/core_extensions'
113
+ require 'pry/basic_object'
114
+ require 'pry/config/behavior'
115
+ require 'pry/config/memoization'
116
+ require 'pry/config/default'
117
+ require 'pry/config/convenience'
118
+ require 'pry/config'
149
119
  require 'pry/pry_class'
150
120
  require 'pry/pry_instance'
151
121
  require 'pry/cli'
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.3
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mair (banisterfiend)
8
8
  - Conrad Irwin
9
9
  - Ryan Fitzgerald
10
+ - Kyrylo Silin
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2017-11-14 00:00:00.000000000 Z
14
+ date: 2018-11-12 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: coderay
@@ -40,25 +41,12 @@ dependencies:
40
41
  - - "~>"
41
42
  - !ruby/object:Gem::Version
42
43
  version: 0.9.0
43
- - !ruby/object:Gem::Dependency
44
- name: bundler
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '1.0'
50
- type: :development
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - "~>"
55
- - !ruby/object:Gem::Version
56
- version: '1.0'
57
44
  description: An IRB alternative and runtime developer console
58
45
  email:
59
46
  - jrmair@gmail.com
60
47
  - conrad.irwin@gmail.com
61
48
  - rwfitzge@gmail.com
49
+ - silin@kyrylo.org
62
50
  executables:
63
51
  - pry
64
52
  extensions: []
@@ -91,6 +79,7 @@ files:
91
79
  - lib/pry/commands/cd.rb
92
80
  - lib/pry/commands/change_inspector.rb
93
81
  - lib/pry/commands/change_prompt.rb
82
+ - lib/pry/commands/clear_screen.rb
94
83
  - lib/pry/commands/code_collector.rb
95
84
  - lib/pry/commands/disable_pry.rb
96
85
  - lib/pry/commands/disabled_commands.rb
@@ -109,6 +98,7 @@ files:
109
98
  - lib/pry/commands/gem_open.rb
110
99
  - lib/pry/commands/gem_readme.rb
111
100
  - lib/pry/commands/gem_search.rb
101
+ - lib/pry/commands/gem_stats.rb
112
102
  - lib/pry/commands/gist.rb
113
103
  - lib/pry/commands/help.rb
114
104
  - lib/pry/commands/hist.rb
@@ -116,7 +106,6 @@ files:
116
106
  - lib/pry/commands/install_command.rb
117
107
  - lib/pry/commands/jump_to.rb
118
108
  - lib/pry/commands/list_inspectors.rb
119
- - lib/pry/commands/list_prompts.rb
120
109
  - lib/pry/commands/ls.rb
121
110
  - lib/pry/commands/ls/constants.rb
122
111
  - lib/pry/commands/ls/formatter.rb
@@ -146,7 +135,6 @@ files:
146
135
  - lib/pry/commands/show_info.rb
147
136
  - lib/pry/commands/show_input.rb
148
137
  - lib/pry/commands/show_source.rb
149
- - lib/pry/commands/simple_prompt.rb
150
138
  - lib/pry/commands/stat.rb
151
139
  - lib/pry/commands/switch_to.rb
152
140
  - lib/pry/commands/toggle_color.rb
@@ -168,10 +156,10 @@ files:
168
156
  - lib/pry/helpers/command_helpers.rb
169
157
  - lib/pry/helpers/documentation_helpers.rb
170
158
  - lib/pry/helpers/options_helpers.rb
159
+ - lib/pry/helpers/platform.rb
171
160
  - lib/pry/helpers/table.rb
172
161
  - lib/pry/helpers/text.rb
173
162
  - lib/pry/history.rb
174
- - lib/pry/history_array.rb
175
163
  - lib/pry/hooks.rb
176
164
  - lib/pry/indent.rb
177
165
  - lib/pry/input_completer.rb
@@ -190,9 +178,9 @@ files:
190
178
  - lib/pry/prompt.rb
191
179
  - lib/pry/pry_class.rb
192
180
  - lib/pry/pry_instance.rb
193
- - lib/pry/rbx_path.rb
194
181
  - lib/pry/repl.rb
195
182
  - lib/pry/repl_file_loader.rb
183
+ - lib/pry/ring.rb
196
184
  - lib/pry/rubygem.rb
197
185
  - lib/pry/slop.rb
198
186
  - lib/pry/slop/LICENSE
@@ -1,35 +0,0 @@
1
- class Pry::Command::ListPrompts < Pry::ClassCommand
2
- match 'list-prompts'
3
- group 'Input and Output'
4
- description 'List the prompts available for use.'
5
- banner <<-BANNER
6
- Usage: list-prompts
7
-
8
- List the available prompts. You can use change-prompt to switch between
9
- them.
10
- BANNER
11
-
12
- def process
13
- output.puts heading("Available prompts") + "\n"
14
- prompt_map.each do |name, prompt|
15
- output.write "Name: #{text.bold(name)}"
16
- output.puts selected_prompt?(prompt) ? selected_text : ""
17
- output.puts prompt[:description]
18
- output.puts
19
- end
20
- end
21
-
22
- private
23
- def prompt_map
24
- Pry::Prompt::MAP
25
- end
26
-
27
- def selected_text
28
- text.red " (selected) "
29
- end
30
-
31
- def selected_prompt?(prompt)
32
- _pry_.prompt == prompt[:value]
33
- end
34
- Pry::Commands.add_command(self)
35
- end
@@ -1,22 +0,0 @@
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
@@ -1,121 +0,0 @@
1
- class Pry
2
- # A history array is an array to which you can only add elements. Older
3
- # entries are removed progressively, so that the array never contains more than
4
- # N elements.
5
- #
6
- # History arrays are used by Pry to store the output of the last commands.
7
- #
8
- # @example
9
- # ary = Pry::HistoryArray.new 10
10
- # ary << 1 << 2 << 3
11
- # ary[0] # => 1
12
- # ary[1] # => 2
13
- # 10.times { |n| ary << n }
14
- # ary[0] # => nil
15
- # ary[-1] # => 9
16
- class HistoryArray
17
- include Enumerable
18
-
19
- # @param [Integer] size Maximum amount of objects in the array
20
- def initialize(size)
21
- @max_size = size
22
-
23
- @hash = {}
24
- @count = 0
25
- end
26
-
27
- # Pushes an object at the end of the array
28
- # @param [Object] value Object to be added
29
- def <<(value)
30
- @hash[@count] = value
31
-
32
- if @hash.size > max_size
33
- @hash.delete(@count - max_size)
34
- end
35
-
36
- @count += 1
37
-
38
- self
39
- end
40
-
41
- # @overload [](index)
42
- # @param [Integer] index Index of the item to access.
43
- # @return [Object, nil] Item at that index or nil if it has been removed.
44
- # @overload [](index, size)
45
- # @param [Integer] index Index of the first item to access.
46
- # @param [Integer] size Amount of items to access
47
- # @return [Array, nil] The selected items. Nil if index is greater than
48
- # the size of the array.
49
- # @overload [](range)
50
- # @param [Range<Integer>] range Range of indices to access.
51
- # @return [Array, nil] The selected items. Nil if index is greater than
52
- # the size of the array.
53
- def [](index_or_range, size = nil)
54
- if index_or_range.is_a? Integer
55
- index = convert_index(index_or_range)
56
-
57
- if size
58
- end_index = index + size
59
- index > @count ? nil : (index...[end_index, @count].min).map do |n|
60
- @hash[n]
61
- end
62
- else
63
- @hash[index]
64
- end
65
- else
66
- range = convert_range(index_or_range)
67
- range.begin > @count ? nil : range.map { |n| @hash[n] }
68
- end
69
- end
70
-
71
- # @return [Integer] Amount of objects in the array
72
- def size
73
- @count
74
- end
75
- alias count size
76
- alias length size
77
-
78
- def empty?
79
- size == 0
80
- end
81
-
82
- def each
83
- ((@count - size)...@count).each do |n|
84
- yield @hash[n]
85
- end
86
- end
87
-
88
- def to_a
89
- ((@count - size)...@count).map { |n| @hash[n] }
90
- end
91
-
92
- # @return [Hash] copy of the internal @hash history
93
- def to_h
94
- @hash.dup
95
- end
96
-
97
- def pop!
98
- @hash.delete @count - 1
99
- @count -= 1
100
- end
101
-
102
- def inspect
103
- "#<#{self.class} size=#{size} first=#{@count - size} max_size=#{max_size}>"
104
- end
105
-
106
- # @return [Integer] Maximum amount of objects in the array
107
- attr_reader :max_size
108
-
109
- private
110
- def convert_index(n)
111
- n >= 0 ? n : @count + n
112
- end
113
-
114
- def convert_range(range)
115
- end_index = convert_index(range.end)
116
- end_index += 1 unless range.exclude_end?
117
-
118
- Range.new(convert_index(range.begin), [end_index, @count].min, true)
119
- end
120
- end
121
- 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