pry 0.11.3 → 0.12.0

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 +5 -5
  2. data/CHANGELOG.md +139 -1
  3. data/LICENSE +1 -1
  4. data/README.md +13 -30
  5. data/bin/pry +0 -4
  6. data/lib/pry.rb +17 -47
  7. data/lib/pry/cli.rb +17 -24
  8. data/lib/pry/code.rb +6 -6
  9. data/lib/pry/code/code_file.rb +5 -4
  10. data/lib/pry/code/code_range.rb +3 -3
  11. data/lib/pry/code/loc.rb +14 -8
  12. data/lib/pry/code_object.rb +4 -4
  13. data/lib/pry/color_printer.rb +1 -0
  14. data/lib/pry/command.rb +36 -29
  15. data/lib/pry/command_set.rb +17 -52
  16. data/lib/pry/commands/amend_line.rb +3 -4
  17. data/lib/pry/commands/bang.rb +1 -1
  18. data/lib/pry/commands/cat.rb +7 -6
  19. data/lib/pry/commands/cat/exception_formatter.rb +9 -8
  20. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  21. data/lib/pry/commands/change_prompt.rb +29 -9
  22. data/lib/pry/commands/clear_screen.rb +14 -0
  23. data/lib/pry/commands/code_collector.rb +9 -9
  24. data/lib/pry/commands/easter_eggs.rb +3 -3
  25. data/lib/pry/commands/edit.rb +8 -7
  26. data/lib/pry/commands/exit.rb +2 -1
  27. data/lib/pry/commands/find_method.rb +11 -13
  28. data/lib/pry/commands/gem_cd.rb +1 -1
  29. data/lib/pry/commands/gem_install.rb +2 -2
  30. data/lib/pry/commands/gem_list.rb +2 -2
  31. data/lib/pry/commands/gem_open.rb +1 -1
  32. data/lib/pry/commands/gem_search.rb +2 -2
  33. data/lib/pry/commands/gem_stats.rb +83 -0
  34. data/lib/pry/commands/gist.rb +7 -6
  35. data/lib/pry/commands/help.rb +3 -3
  36. data/lib/pry/commands/hist.rb +9 -8
  37. data/lib/pry/commands/import_set.rb +2 -1
  38. data/lib/pry/commands/install_command.rb +7 -6
  39. data/lib/pry/commands/list_inspectors.rb +2 -2
  40. data/lib/pry/commands/ls.rb +27 -30
  41. data/lib/pry/commands/ls/constants.rb +4 -4
  42. data/lib/pry/commands/ls/formatter.rb +3 -2
  43. data/lib/pry/commands/ls/globals.rb +0 -2
  44. data/lib/pry/commands/ls/grep.rb +0 -2
  45. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  46. data/lib/pry/commands/ls/local_names.rb +0 -2
  47. data/lib/pry/commands/ls/local_vars.rb +0 -2
  48. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  49. data/lib/pry/commands/ls/methods.rb +0 -3
  50. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  51. data/lib/pry/commands/ls/self_methods.rb +0 -1
  52. data/lib/pry/commands/play.rb +1 -2
  53. data/lib/pry/commands/pry_backtrace.rb +1 -1
  54. data/lib/pry/commands/raise_up.rb +2 -1
  55. data/lib/pry/commands/ri.rb +5 -4
  56. data/lib/pry/commands/shell_command.rb +3 -2
  57. data/lib/pry/commands/shell_mode.rb +6 -6
  58. data/lib/pry/commands/show_doc.rb +5 -7
  59. data/lib/pry/commands/show_info.rb +25 -18
  60. data/lib/pry/commands/show_source.rb +5 -2
  61. data/lib/pry/commands/stat.rb +1 -1
  62. data/lib/pry/commands/watch_expression.rb +9 -7
  63. data/lib/pry/commands/whereami.rb +4 -4
  64. data/lib/pry/commands/wtf.rb +15 -2
  65. data/lib/pry/config.rb +33 -9
  66. data/lib/pry/config/behavior.rb +229 -205
  67. data/lib/pry/config/convenience.rb +24 -21
  68. data/lib/pry/config/default.rb +153 -143
  69. data/lib/pry/config/memoization.rb +41 -37
  70. data/lib/pry/core_extensions.rb +4 -3
  71. data/lib/pry/editor.rb +5 -12
  72. data/lib/pry/exceptions.rb +0 -2
  73. data/lib/pry/helpers.rb +1 -0
  74. data/lib/pry/helpers/base_helpers.rb +133 -4
  75. data/lib/pry/helpers/command_helpers.rb +5 -4
  76. data/lib/pry/helpers/documentation_helpers.rb +2 -2
  77. data/lib/pry/helpers/options_helpers.rb +5 -5
  78. data/lib/pry/helpers/platform.rb +58 -0
  79. data/lib/pry/helpers/table.rb +20 -15
  80. data/lib/pry/helpers/text.rb +3 -4
  81. data/lib/pry/history.rb +21 -8
  82. data/lib/pry/hooks.rb +3 -3
  83. data/lib/pry/indent.rb +15 -17
  84. data/lib/pry/input_completer.rb +12 -7
  85. data/lib/pry/input_lock.rb +0 -2
  86. data/lib/pry/last_exception.rb +1 -1
  87. data/lib/pry/method.rb +37 -31
  88. data/lib/pry/method/disowned.rb +2 -1
  89. data/lib/pry/method/patcher.rb +2 -2
  90. data/lib/pry/method/weird_method_locator.rb +7 -8
  91. data/lib/pry/object_path.rb +5 -4
  92. data/lib/pry/output.rb +3 -2
  93. data/lib/pry/pager.rb +4 -3
  94. data/lib/pry/platform.rb +79 -81
  95. data/lib/pry/plugins.rb +7 -3
  96. data/lib/pry/prompt.rb +144 -25
  97. data/lib/pry/pry_class.rb +53 -29
  98. data/lib/pry/pry_instance.rb +88 -55
  99. data/lib/pry/repl.rb +33 -4
  100. data/lib/pry/repl_file_loader.rb +1 -2
  101. data/lib/pry/ring.rb +84 -0
  102. data/lib/pry/rubygem.rb +6 -6
  103. data/lib/pry/slop.rb +17 -17
  104. data/lib/pry/slop/commands.rb +3 -4
  105. data/lib/pry/slop/option.rb +19 -21
  106. data/lib/pry/terminal.rb +2 -1
  107. data/lib/pry/testable/mockable.rb +2 -2
  108. data/lib/pry/testable/pry_tester.rb +1 -1
  109. data/lib/pry/testable/utility.rb +2 -2
  110. data/lib/pry/testable/variables.rb +1 -1
  111. data/lib/pry/version.rb +1 -1
  112. data/lib/pry/wrapped_module.rb +15 -15
  113. data/lib/pry/wrapped_module/candidate.rb +2 -2
  114. metadata +17 -29
  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
@@ -3,7 +3,7 @@ class Pry
3
3
  match(/wtf([?!]*)/)
4
4
  group 'Context'
5
5
  description 'Show the backtrace of the most recent exception.'
6
- options :listing => 'wtf?'
6
+ options listing: 'wtf?'
7
7
 
8
8
  banner <<-'BANNER'
9
9
  Usage: wtf[?|!]
@@ -26,12 +26,25 @@ class Pry
26
26
  def process
27
27
  raise Pry::CommandError, "No most-recent exception" unless exception
28
28
 
29
- output.puts "#{text.bold('Exception:')} #{exception.class}: #{exception}\n--"
29
+ output.puts "#{bold('Exception:')} #{exception.class}: #{exception}\n--"
30
30
  if opts.verbose?
31
31
  output.puts with_line_numbers(backtrace)
32
32
  else
33
33
  output.puts with_line_numbers(backtrace.first(size_of_backtrace))
34
34
  end
35
+
36
+ if exception.respond_to? :cause
37
+ cause = exception.cause
38
+ while cause
39
+ output.puts "#{text.bold('Caused by:')} #{cause.class}: #{cause}\n--"
40
+ if opts.verbose?
41
+ output.puts with_line_numbers(cause.backtrace)
42
+ else
43
+ output.puts with_line_numbers(cause.backtrace.first(size_of_backtrace))
44
+ end
45
+ cause = cause.cause
46
+ end
47
+ end
35
48
  end
36
49
 
37
50
  private
@@ -1,11 +1,35 @@
1
- require_relative 'basic_object'
2
- class Pry::Config < Pry::BasicObject
3
- require_relative 'config/behavior'
4
- require_relative 'config/memoization'
5
- require_relative 'config/default'
6
- require_relative 'config/convenience'
7
- include Pry::Config::Behavior
8
- def self.shortcuts
9
- Convenience::SHORTCUTS
1
+ class Pry
2
+ # The Pry config.
3
+ # @api public
4
+ class Config < Pry::BasicObject
5
+ # Wraps a block so it can have a name.
6
+ #
7
+ # @example
8
+ # proc1 = proc {}
9
+ # proc2 = Pry::Config::Lazy.new(&proc {})
10
+ #
11
+ # proc1.is_a?(Pry::Config::Lazy)
12
+ # #=> false
13
+ # proc2.is_a?(Pry::Config::Lazy)
14
+ # #=> true
15
+ #
16
+ # @api private
17
+ # @since v0.12.0
18
+ class Lazy
19
+ def initialize(&block)
20
+ @block = block
21
+ end
22
+
23
+ # @return [Object]
24
+ def call
25
+ @block.call
26
+ end
27
+ end
28
+
29
+ include Behavior
30
+
31
+ def self.shortcuts
32
+ Convenience::SHORTCUTS
33
+ end
10
34
  end
11
35
  end
@@ -1,231 +1,255 @@
1
- module Pry::Config::Behavior
2
- ASSIGNMENT = "=".freeze
3
- NODUP = [TrueClass, FalseClass, NilClass, Symbol, Numeric, Module, Proc].freeze
4
- INSPECT_REGEXP = /#{Regexp.escape "default=#<"}/
5
- ReservedKeyError = Class.new(RuntimeError)
6
-
7
- module Builder
8
- #
9
- # @param [Hash] attributes
10
- # a hash to initialize an instance of self with.
11
- #
12
- # @param [Pry::Config, nil] default
13
- # a default, or nil for none.
14
- #
15
- # @return [Pry::Config]
16
- # returns an instance of self.
17
- #
18
- def from_hash(attributes, default = nil)
19
- new(default).tap do |config|
20
- attributes.each do |key,value|
21
- config[key] = Hash === value ? from_hash(value, nil) : value
1
+ class Pry
2
+ class Config < Pry::BasicObject
3
+ module Behavior
4
+ ASSIGNMENT = "=".freeze
5
+ NODUP = [TrueClass, FalseClass, NilClass, Symbol, Numeric, Module, Proc].freeze
6
+ INSPECT_REGEXP = /#{Regexp.escape "default=#<"}/
7
+ ReservedKeyError = Class.new(RuntimeError)
8
+
9
+ module Builder
10
+ #
11
+ # Returns a new Behavior, non-recursively (unlike {#from_hash}).
12
+ #
13
+ # @param
14
+ # (see #from_hash)
15
+ #
16
+ # @return
17
+ # (see #from_hash)
18
+ #
19
+ def assign(attributes, default = nil)
20
+ new(default).tap do |behavior|
21
+ behavior.merge!(attributes)
22
+ end
23
+ end
24
+
25
+ #
26
+ # Returns a new Behavior, recursively walking attributes.
27
+ #
28
+ # @param [Hash] attributes
29
+ # a hash to initialize an instance of self with.
30
+ #
31
+ # @param [Pry::Config, nil] default
32
+ # a default, or nil for none.
33
+ #
34
+ # @return [Pry::Config]
35
+ # returns an instance of self.
36
+ #
37
+ def from_hash(attributes, default = nil)
38
+ new(default).tap do |config|
39
+ attributes.each do |key,value|
40
+ config[key] = Hash === value ? from_hash(value, nil) : value
41
+ end
42
+ end
22
43
  end
23
44
  end
24
- end
25
- end
26
45
 
27
- def self.included(klass)
28
- klass.extend(Builder)
29
- end
46
+ def self.included(klass)
47
+ klass.extend(Builder)
48
+ end
30
49
 
31
- def initialize(default = Pry.config)
32
- @default = default
33
- @lookup = {}
34
- @reserved_keys = methods.map(&:to_s).freeze
35
- end
50
+ def initialize(default = Pry.config)
51
+ @default = default
52
+ @lookup = {}
53
+ @reserved_keys = methods.map(&:to_s).freeze
54
+ end
36
55
 
37
- #
38
- # @return [Pry::Config::Behavior]
39
- # returns the default used incase a key isn't found in self.
40
- #
41
- def default
42
- @default
43
- end
56
+ #
57
+ # @return [Pry::Config::Behavior]
58
+ # returns the default used incase a key isn't found in self.
59
+ #
60
+ def default
61
+ @default
62
+ end
44
63
 
45
- #
46
- # @param [String] key
47
- # a key (as a String)
48
- #
49
- # @return [Object, BasicObject]
50
- # returns an object from self or one of its defaults.
51
- #
52
- def [](key)
53
- key = key.to_s
54
- key?(key) ? @lookup[key] : (@default and @default[key])
55
- end
64
+ #
65
+ # @param [String] key
66
+ # a key (as a String)
67
+ #
68
+ # @return [Object, BasicObject]
69
+ # returns an object from self or one of its defaults.
70
+ #
71
+ def [](key)
72
+ key = key.to_s
73
+ key?(key) ? @lookup[key] : (@default and @default[key])
74
+ end
56
75
 
57
- #
58
- # Add a key and value pair to self.
59
- #
60
- # @param [String] key
61
- # a key (as a String).
62
- #
63
- # @param [Object,BasicObject] value
64
- # a value.
65
- #
66
- # @raise [Pry::Config::ReservedKeyError]
67
- # when 'key' is a reserved key name.
68
- #
69
- def []=(key, value)
70
- key = key.to_s
71
- if @reserved_keys.include?(key)
72
- raise ReservedKeyError, "It is not possible to use '#{key}' as a key name, please choose a different key name."
73
- end
74
- __push(key,value)
75
- end
76
+ #
77
+ # Add a key and value pair to self.
78
+ #
79
+ # @param [String] key
80
+ # a key (as a String).
81
+ #
82
+ # @param [Object,BasicObject] value
83
+ # a value.
84
+ #
85
+ # @raise [Pry::Config::ReservedKeyError]
86
+ # when 'key' is a reserved key name.
87
+ #
88
+ def []=(key, value)
89
+ key = key.to_s
90
+ if @reserved_keys.include?(key)
91
+ raise ReservedKeyError, "It is not possible to use '#{key}' as a key name, please choose a different key name."
92
+ end
76
93
 
77
- #
78
- # Removes a key from self.
79
- #
80
- # @param [String] key
81
- # a key (as a String)
82
- #
83
- # @return [void]
84
- #
85
- def forget(key)
86
- key = key.to_s
87
- __remove(key)
88
- end
94
+ __push(key,value)
95
+ end
89
96
 
90
- #
91
- # @param [Hash, #to_h, #to_hash] other
92
- # a hash to merge into self.
93
- #
94
- # @return [void]
95
- #
96
- def merge!(other)
97
- other = __try_convert_to_hash(other)
98
- raise TypeError, "unable to convert argument into a Hash" unless other
99
- other.each do |key, value|
100
- self[key] = value
101
- end
102
- end
97
+ #
98
+ # Removes a key from self.
99
+ #
100
+ # @param [String] key
101
+ # a key (as a String)
102
+ #
103
+ # @return [void]
104
+ #
105
+ def forget(key)
106
+ key = key.to_s
107
+ __remove(key)
108
+ end
103
109
 
104
- #
105
- # @param [Hash, #to_h, #to_hash] other
106
- # a hash to compare against the lookup table of self.
107
- #
108
- def ==(other)
109
- @lookup == __try_convert_to_hash(other)
110
- end
111
- alias_method :eql?, :==
112
-
113
- #
114
- # @param [String] key
115
- # a key (as a String)
116
- #
117
- # @return [Boolean]
118
- # returns true when "key" is a member of self.
119
- #
120
- def key?(key)
121
- key = key.to_s
122
- @lookup.key?(key)
123
- end
110
+ #
111
+ # @param [Hash, #to_h, #to_hash] other
112
+ # a hash to merge into self.
113
+ #
114
+ # @return [void]
115
+ #
116
+ def merge!(other)
117
+ other = __try_convert_to_hash(other)
118
+ raise TypeError, "unable to convert argument into a Hash" unless other
119
+
120
+ other.each do |key, value|
121
+ self[key] = value
122
+ end
123
+ end
124
124
 
125
- #
126
- # Clear the lookup table of self.
127
- #
128
- # @return [void]
129
- #
130
- def clear
131
- @lookup.clear
132
- true
133
- end
125
+ #
126
+ # @param [Hash, #to_h, #to_hash] other
127
+ # a hash to compare against the lookup table of self.
128
+ #
129
+ def ==(other)
130
+ @lookup == __try_convert_to_hash(other)
131
+ end
132
+ alias_method :eql?, :==
133
+
134
+ #
135
+ # @param [String] key
136
+ # a key (as a String)
137
+ #
138
+ # @return [Boolean]
139
+ # returns true when "key" is a member of self.
140
+ #
141
+ def key?(key)
142
+ key = key.to_s
143
+ @lookup.key?(key)
144
+ end
134
145
 
135
- #
136
- # @return [Array<String>]
137
- # returns an array of keys in self.
138
- #
139
- def keys
140
- @lookup.keys
141
- end
146
+ #
147
+ # Clear the lookup table of self.
148
+ #
149
+ # @return [void]
150
+ #
151
+ def clear
152
+ @lookup.clear
153
+ true
154
+ end
142
155
 
143
- def eager_load!
144
- default = @default
145
- while default
146
- default.memoized_methods.each {|method| self[key] = default.public_send(key)} if default.respond_to?(:memoized_methods)
147
- default = @default.default
148
- end
149
- end
156
+ #
157
+ # @return [Array<String>]
158
+ # returns an array of keys in self.
159
+ #
160
+ def keys
161
+ @lookup.keys
162
+ end
150
163
 
151
- def last_default
152
- last = @default
153
- last = last.default while last and last.default
154
- last
155
- end
164
+ def eager_load!
165
+ default = @default
166
+ while default
167
+ default.memoized_methods.each { |method| self[key] = default.public_send(key) } if default.respond_to?(:memoized_methods)
168
+ default = @default.default
169
+ end
170
+ end
156
171
 
157
- #
158
- # @return [Hash]
159
- # returns a duplicate copy of the lookup table used by self.
160
- #
161
- def to_hash
162
- @lookup.dup
163
- end
164
- alias_method :to_h, :to_hash
172
+ def last_default
173
+ last = @default
174
+ last = last.default while last and last.default
175
+ last
176
+ end
165
177
 
166
- def inspect
167
- key_str = keys.map { |key| "'#{key}'" }.join(",")
168
- "#<#{__clip_inspect(self)} keys=[#{key_str}] default=#{@default.inspect}>"
169
- end
178
+ #
179
+ # @return [Hash]
180
+ # returns a duplicate copy of the lookup table used by self.
181
+ #
182
+ def to_hash
183
+ @lookup.dup
184
+ end
185
+ alias_method :to_h, :to_hash
170
186
 
171
- def pretty_print(q)
172
- q.text inspect[1..-1].gsub(INSPECT_REGEXP, "default=<")
173
- end
187
+ def inspect
188
+ key_str = keys.map { |key| "'#{key}'" }.join(",")
189
+ "#<#{__clip_inspect(self)} keys=[#{key_str}] default=#{@default.inspect}>"
190
+ end
174
191
 
175
- def method_missing(name, *args, &block)
176
- key = name.to_s
177
- if key[-1] == ASSIGNMENT
178
- short_key = key[0..-2]
179
- self[short_key] = args[0]
180
- elsif key?(key)
181
- self[key]
182
- elsif @default.respond_to?(name)
183
- value = @default.public_send(name, *args, &block)
184
- self[key] = __dup(value)
185
- else
186
- nil
187
- end
188
- end
192
+ def pretty_print(q)
193
+ q.text inspect[1..-1].gsub(INSPECT_REGEXP, "default=<")
194
+ end
189
195
 
190
- def respond_to_missing?(key, include_all=false)
191
- key = key.to_s.chomp(ASSIGNMENT)
192
- key?(key) or @default.respond_to?(key) or super(key, include_all)
193
- end
196
+ def method_missing(name, *args, &block)
197
+ key = name.to_s
198
+ if key[-1] == ASSIGNMENT
199
+ short_key = key[0..-2]
200
+ self[short_key] = args[0]
201
+ elsif key?(key)
202
+ self[key]
203
+ elsif @default.respond_to?(name)
204
+ value = @default.public_send(name, *args, &block)
205
+ self[key] = __dup(value)
206
+ else
207
+ nil
208
+ end
209
+ end
194
210
 
195
- private
196
- def __clip_inspect(obj)
197
- "#{obj.class}:0x%x" % obj.object_id
198
- end
211
+ def respond_to_missing?(key, include_all = false)
212
+ key = key.to_s.chomp(ASSIGNMENT)
213
+ key?(key) or @default.respond_to?(key) or super(key, include_all)
214
+ end
199
215
 
200
- def __try_convert_to_hash(obj)
201
- if Hash === obj
202
- obj
203
- elsif obj.respond_to?(:to_h)
204
- obj.to_h
205
- elsif obj.respond_to?(:to_hash)
206
- obj.to_hash
207
- else
208
- nil
209
- end
210
- end
216
+ private
211
217
 
212
- def __dup(value)
213
- if NODUP.any? { |klass| klass === value }
214
- value
215
- else
216
- value.dup
217
- end
218
- end
218
+ def __clip_inspect(obj)
219
+ "#{obj.class}:0x%x" % obj.object_id
220
+ end
219
221
 
220
- def __push(key,value)
221
- unless singleton_class.method_defined? key
222
- define_singleton_method(key) { self[key] }
223
- define_singleton_method("#{key}=") { |val| @lookup[key] = val }
224
- end
225
- @lookup[key] = value
226
- end
222
+ def __try_convert_to_hash(obj)
223
+ if Hash === obj
224
+ obj
225
+ elsif obj.respond_to?(:to_h)
226
+ obj.to_h
227
+ elsif obj.respond_to?(:to_hash)
228
+ obj.to_hash
229
+ else
230
+ nil
231
+ end
232
+ end
227
233
 
228
- def __remove(key)
229
- @lookup.delete(key)
234
+ def __dup(value)
235
+ if NODUP.any? { |klass| klass === value }
236
+ value
237
+ else
238
+ value.dup
239
+ end
240
+ end
241
+
242
+ def __push(key,value)
243
+ unless singleton_class.method_defined? key
244
+ define_singleton_method(key) { self[key] }
245
+ define_singleton_method("#{key}=") { |val| @lookup[key] = val }
246
+ end
247
+ @lookup[key] = value
248
+ end
249
+
250
+ def __remove(key)
251
+ @lookup.delete(key)
252
+ end
253
+ end
230
254
  end
231
255
  end