pry 0.10.3 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +251 -16
  3. data/LICENSE +1 -1
  4. data/README.md +35 -51
  5. data/bin/pry +3 -11
  6. data/lib/pry/basic_object.rb +6 -0
  7. data/lib/pry/cli.rb +50 -52
  8. data/lib/pry/code/code_file.rb +13 -6
  9. data/lib/pry/code/code_range.rb +3 -3
  10. data/lib/pry/code/loc.rb +14 -8
  11. data/lib/pry/code.rb +12 -5
  12. data/lib/pry/code_object.rb +27 -4
  13. data/lib/pry/color_printer.rb +20 -10
  14. data/lib/pry/command.rb +76 -45
  15. data/lib/pry/command_set.rb +17 -45
  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/exception_formatter.rb +10 -8
  19. data/lib/pry/commands/cat/file_formatter.rb +7 -3
  20. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  21. data/lib/pry/commands/cat.rb +7 -6
  22. data/lib/pry/commands/change_prompt.rb +29 -9
  23. data/lib/pry/commands/clear_screen.rb +14 -0
  24. data/lib/pry/commands/code_collector.rb +25 -23
  25. data/lib/pry/commands/easter_eggs.rb +12 -12
  26. data/lib/pry/commands/edit/file_and_line_locator.rb +1 -1
  27. data/lib/pry/commands/edit.rb +15 -10
  28. data/lib/pry/commands/exit.rb +2 -1
  29. data/lib/pry/commands/find_method.rb +12 -14
  30. data/lib/pry/commands/gem_cd.rb +1 -1
  31. data/lib/pry/commands/gem_install.rb +2 -2
  32. data/lib/pry/commands/gem_list.rb +2 -2
  33. data/lib/pry/commands/gem_open.rb +2 -2
  34. data/lib/pry/commands/gem_readme.rb +25 -0
  35. data/lib/pry/commands/gem_search.rb +40 -0
  36. data/lib/pry/commands/gem_stats.rb +83 -0
  37. data/lib/pry/commands/gist.rb +7 -6
  38. data/lib/pry/commands/help.rb +3 -3
  39. data/lib/pry/commands/hist.rb +11 -10
  40. data/lib/pry/commands/import_set.rb +2 -1
  41. data/lib/pry/commands/install_command.rb +7 -6
  42. data/lib/pry/commands/jump_to.rb +7 -7
  43. data/lib/pry/commands/list_inspectors.rb +2 -2
  44. data/lib/pry/commands/ls/constants.rb +14 -3
  45. data/lib/pry/commands/ls/formatter.rb +4 -2
  46. data/lib/pry/commands/ls/globals.rb +0 -2
  47. data/lib/pry/commands/ls/grep.rb +0 -2
  48. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  49. data/lib/pry/commands/ls/jruby_hacks.rb +2 -2
  50. data/lib/pry/commands/ls/local_names.rb +0 -2
  51. data/lib/pry/commands/ls/local_vars.rb +0 -2
  52. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  53. data/lib/pry/commands/ls/methods.rb +0 -3
  54. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  55. data/lib/pry/commands/ls/self_methods.rb +2 -1
  56. data/lib/pry/commands/ls.rb +30 -31
  57. data/lib/pry/commands/play.rb +3 -4
  58. data/lib/pry/commands/pry_backtrace.rb +1 -1
  59. data/lib/pry/commands/raise_up.rb +2 -1
  60. data/lib/pry/commands/reload_code.rb +2 -2
  61. data/lib/pry/commands/ri.rb +9 -4
  62. data/lib/pry/commands/shell_command.rb +36 -9
  63. data/lib/pry/commands/shell_mode.rb +6 -6
  64. data/lib/pry/commands/show_doc.rb +5 -7
  65. data/lib/pry/commands/show_info.rb +41 -20
  66. data/lib/pry/commands/show_source.rb +5 -2
  67. data/lib/pry/commands/stat.rb +1 -1
  68. data/lib/pry/commands/watch_expression/expression.rb +1 -1
  69. data/lib/pry/commands/watch_expression.rb +9 -7
  70. data/lib/pry/commands/whereami.rb +16 -9
  71. data/lib/pry/commands/wtf.rb +15 -2
  72. data/lib/pry/config/behavior.rb +230 -114
  73. data/lib/pry/config/convenience.rb +24 -21
  74. data/lib/pry/config/default.rb +151 -153
  75. data/lib/pry/config/memoization.rb +48 -0
  76. data/lib/pry/config.rb +30 -19
  77. data/lib/pry/core_extensions.rb +15 -4
  78. data/lib/pry/editor.rb +5 -12
  79. data/lib/pry/exceptions.rb +1 -3
  80. data/lib/pry/forwardable.rb +23 -0
  81. data/lib/pry/helpers/base_helpers.rb +197 -110
  82. data/lib/pry/helpers/command_helpers.rb +5 -4
  83. data/lib/pry/helpers/documentation_helpers.rb +3 -2
  84. data/lib/pry/helpers/options_helpers.rb +6 -6
  85. data/lib/pry/helpers/platform.rb +58 -0
  86. data/lib/pry/helpers/table.rb +20 -15
  87. data/lib/pry/helpers/text.rb +82 -74
  88. data/lib/pry/helpers.rb +1 -0
  89. data/lib/pry/history.rb +44 -10
  90. data/lib/pry/hooks.rb +50 -109
  91. data/lib/pry/indent.rb +21 -19
  92. data/lib/pry/input_completer.rb +146 -123
  93. data/lib/pry/input_lock.rb +0 -2
  94. data/lib/pry/last_exception.rb +2 -2
  95. data/lib/pry/method/disowned.rb +3 -1
  96. data/lib/pry/method/patcher.rb +2 -5
  97. data/lib/pry/method/weird_method_locator.rb +21 -11
  98. data/lib/pry/method.rb +44 -38
  99. data/lib/pry/object_path.rb +5 -4
  100. data/lib/pry/output.rb +37 -37
  101. data/lib/pry/pager.rb +195 -181
  102. data/lib/pry/platform.rb +91 -0
  103. data/lib/pry/plugins.rb +27 -8
  104. data/lib/pry/prompt.rb +144 -25
  105. data/lib/pry/pry_class.rb +83 -33
  106. data/lib/pry/pry_instance.rb +94 -59
  107. data/lib/pry/repl.rb +70 -11
  108. data/lib/pry/repl_file_loader.rb +2 -3
  109. data/lib/pry/ring.rb +84 -0
  110. data/lib/pry/rubygem.rb +9 -7
  111. data/lib/pry/slop/LICENSE +20 -0
  112. data/lib/pry/slop/commands.rb +195 -0
  113. data/lib/pry/slop/option.rb +206 -0
  114. data/lib/pry/slop.rb +661 -0
  115. data/lib/pry/terminal.rb +18 -6
  116. data/lib/pry/testable/evalable.rb +15 -0
  117. data/lib/pry/testable/mockable.rb +14 -0
  118. data/lib/pry/testable/pry_tester.rb +73 -0
  119. data/lib/pry/testable/utility.rb +26 -0
  120. data/lib/pry/testable/variables.rb +46 -0
  121. data/lib/pry/testable.rb +70 -0
  122. data/lib/pry/version.rb +1 -1
  123. data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +9 -14
  124. data/lib/pry/wrapped_module.rb +22 -21
  125. data/lib/pry.rb +21 -50
  126. metadata +35 -46
  127. data/lib/pry/commands/list_prompts.rb +0 -35
  128. data/lib/pry/commands/simple_prompt.rb +0 -22
  129. data/lib/pry/history_array.rb +0 -121
  130. data/lib/pry/rbx_path.rb +0 -22
  131. data/lib/pry/test/helper.rb +0 -170
@@ -1,139 +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=#<"}/
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
43
+ end
44
+ end
5
45
 
6
- module Builder
7
- def from_hash(hash, default = nil)
8
- new(default).tap do |config|
9
- config.merge!(hash)
46
+ def self.included(klass)
47
+ klass.extend(Builder)
10
48
  end
11
- end
12
- end
13
49
 
14
- def self.included(klass)
15
- unless defined?(RESERVED_KEYS)
16
- const_set :RESERVED_KEYS, instance_methods(false).map(&:to_s).freeze
17
- end
18
- klass.extend(Builder)
19
- end
50
+ def initialize(default = Pry.config)
51
+ @default = default
52
+ @lookup = {}
53
+ @reserved_keys = methods.map(&:to_s).freeze
54
+ end
20
55
 
21
- def initialize(default = Pry.config)
22
- @default = default
23
- @lookup = {}
24
- 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
25
63
 
26
- #
27
- # @return [Pry::Config::Behavior]
28
- # returns the default used if a matching value for a key isn't found in self
29
- #
30
- def default
31
- @default
32
- 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
33
75
 
34
- def [](key)
35
- @lookup[key.to_s]
36
- 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
93
+
94
+ __push(key,value)
95
+ end
37
96
 
38
- def []=(key, value)
39
- key = key.to_s
40
- if RESERVED_KEYS.include?(key)
41
- raise ArgumentError, "few things are reserved by pry, but using '#{key}' as a configuration key is."
42
- end
43
- @lookup[key] = value
44
- 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
45
109
 
46
- def method_missing(name, *args, &block)
47
- key = name.to_s
48
- if key[-1] == ASSIGNMENT
49
- short_key = key[0..-2]
50
- self[short_key] = args[0]
51
- elsif key?(key)
52
- self[key]
53
- elsif @default.respond_to?(name)
54
- value = @default.public_send(name, *args, &block)
55
- # FIXME: refactor Pry::Hook so that it stores config on the config object,
56
- # so that we can use the normal strategy.
57
- self[key] = value = value.dup if key == 'hooks'
58
- value
59
- else
60
- nil
61
- end
62
- 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
63
124
 
64
- def merge!(other)
65
- other = try_convert_to_hash(other)
66
- raise TypeError, "unable to convert argument into a Hash" unless other
67
- other.each do |key, value|
68
- self[key] = value
69
- end
70
- 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
71
145
 
72
- def ==(other)
73
- @lookup == try_convert_to_hash(other)
74
- end
75
- alias_method :eql?, :==
146
+ #
147
+ # Clear the lookup table of self.
148
+ #
149
+ # @return [void]
150
+ #
151
+ def clear
152
+ @lookup.clear
153
+ true
154
+ end
76
155
 
77
- def respond_to_missing?(key, include_private=false)
78
- key?(key) or @default.respond_to?(key) or super(key, include_private)
79
- end
156
+ #
157
+ # @return [Array<String>]
158
+ # returns an array of keys in self.
159
+ #
160
+ def keys
161
+ @lookup.keys
162
+ end
80
163
 
81
- def key?(key)
82
- key = key.to_s
83
- @lookup.key?(key)
84
- 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
85
171
 
86
- def clear
87
- @lookup.clear
88
- true
89
- end
90
- alias_method :refresh, :clear
172
+ def last_default
173
+ last = @default
174
+ last = last.default while last and last.default
175
+ last
176
+ end
91
177
 
92
- def forget(key)
93
- @lookup.delete(key.to_s)
94
- 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
95
186
 
96
- def keys
97
- @lookup.keys
98
- end
187
+ def inspect
188
+ key_str = keys.map { |key| "'#{key}'" }.join(",")
189
+ "#<#{__clip_inspect(self)} keys=[#{key_str}] default=#{@default.inspect}>"
190
+ end
99
191
 
100
- def to_hash
101
- @lookup.dup
102
- end
103
- alias_method :to_h, :to_hash
192
+ def pretty_print(q)
193
+ q.text inspect[1..-1].gsub(INSPECT_REGEXP, "default=<")
194
+ end
104
195
 
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
105
210
 
106
- def inspect
107
- key_str = keys.map { |key| "'#{key}'" }.join(",")
108
- "#<#{_clip_inspect(self)} local_keys=[#{key_str}] default=#{@default.inspect}>"
109
- 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
110
215
 
111
- def pretty_print(q)
112
- q.text inspect[1..-1].gsub(INSPECT_REGEXP, "default=<")
113
- end
216
+ private
114
217
 
115
- private
116
- def _clip_inspect(obj)
117
- "#{obj.class}:0x%x" % obj.object_id << 1
118
- end
218
+ def __clip_inspect(obj)
219
+ "#{obj.class}:0x%x" % obj.object_id
220
+ end
119
221
 
120
- def _dup(value)
121
- if NODUP.any? { |klass| klass === value }
122
- value
123
- else
124
- value.dup
125
- end
126
- 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
233
+
234
+ def __dup(value)
235
+ if NODUP.any? { |klass| klass === value }
236
+ value
237
+ else
238
+ value.dup
239
+ end
240
+ end
127
241
 
128
- def try_convert_to_hash(obj)
129
- if Hash === obj
130
- obj
131
- elsif obj.respond_to?(:to_h)
132
- obj.to_h
133
- elsif obj.respond_to?(:to_hash)
134
- obj.to_hash
135
- else
136
- nil
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
137
253
  end
138
254
  end
139
255
  end
@@ -1,25 +1,28 @@
1
- module Pry::Config::Convenience
2
- SHORTCUTS = [
3
- :input,
4
- :output,
5
- :commands,
6
- :print,
7
- :exception_handler,
8
- :hooks,
9
- :color,
10
- :pager,
11
- :editor,
12
- :memory_size,
13
- :extra_sticky_locals
14
- ]
1
+ class Pry
2
+ class Config < Pry::BasicObject
3
+ module Convenience
4
+ SHORTCUTS = [
5
+ :input,
6
+ :output,
7
+ :commands,
8
+ :print,
9
+ :exception_handler,
10
+ :hooks,
11
+ :color,
12
+ :pager,
13
+ :editor,
14
+ :memory_size,
15
+ :extra_sticky_locals
16
+ ]
15
17
 
16
-
17
- def config_shortcut(*names)
18
- names.each do |name|
19
- reader = name
20
- setter = "#{name}="
21
- define_method(reader) { config.public_send(name) }
22
- define_method(setter) { |value| config.public_send(setter, value) }
18
+ def config_shortcut(*names)
19
+ names.each do |name|
20
+ reader = name
21
+ setter = "#{name}="
22
+ define_method(reader) { config.public_send(name) }
23
+ define_method(setter) { |value| config.public_send(setter, value) }
24
+ end
25
+ end
23
26
  end
24
27
  end
25
28
  end