pry 0.10.3 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +251 -16
- data/LICENSE +1 -1
- data/README.md +35 -51
- data/bin/pry +3 -11
- data/lib/pry/basic_object.rb +6 -0
- data/lib/pry/cli.rb +50 -52
- data/lib/pry/code/code_file.rb +13 -6
- data/lib/pry/code/code_range.rb +3 -3
- data/lib/pry/code/loc.rb +14 -8
- data/lib/pry/code.rb +12 -5
- data/lib/pry/code_object.rb +27 -4
- data/lib/pry/color_printer.rb +20 -10
- data/lib/pry/command.rb +76 -45
- data/lib/pry/command_set.rb +17 -45
- data/lib/pry/commands/amend_line.rb +3 -4
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat/exception_formatter.rb +10 -8
- data/lib/pry/commands/cat/file_formatter.rb +7 -3
- data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
- data/lib/pry/commands/cat.rb +7 -6
- data/lib/pry/commands/change_prompt.rb +29 -9
- data/lib/pry/commands/clear_screen.rb +14 -0
- data/lib/pry/commands/code_collector.rb +25 -23
- data/lib/pry/commands/easter_eggs.rb +12 -12
- data/lib/pry/commands/edit/file_and_line_locator.rb +1 -1
- data/lib/pry/commands/edit.rb +15 -10
- data/lib/pry/commands/exit.rb +2 -1
- data/lib/pry/commands/find_method.rb +12 -14
- data/lib/pry/commands/gem_cd.rb +1 -1
- data/lib/pry/commands/gem_install.rb +2 -2
- data/lib/pry/commands/gem_list.rb +2 -2
- data/lib/pry/commands/gem_open.rb +2 -2
- data/lib/pry/commands/gem_readme.rb +25 -0
- data/lib/pry/commands/gem_search.rb +40 -0
- data/lib/pry/commands/gem_stats.rb +83 -0
- data/lib/pry/commands/gist.rb +7 -6
- data/lib/pry/commands/help.rb +3 -3
- data/lib/pry/commands/hist.rb +11 -10
- data/lib/pry/commands/import_set.rb +2 -1
- data/lib/pry/commands/install_command.rb +7 -6
- data/lib/pry/commands/jump_to.rb +7 -7
- data/lib/pry/commands/list_inspectors.rb +2 -2
- data/lib/pry/commands/ls/constants.rb +14 -3
- data/lib/pry/commands/ls/formatter.rb +4 -2
- data/lib/pry/commands/ls/globals.rb +0 -2
- data/lib/pry/commands/ls/grep.rb +0 -2
- data/lib/pry/commands/ls/instance_vars.rb +0 -1
- data/lib/pry/commands/ls/jruby_hacks.rb +2 -2
- data/lib/pry/commands/ls/local_names.rb +0 -2
- data/lib/pry/commands/ls/local_vars.rb +0 -2
- data/lib/pry/commands/ls/ls_entity.rb +0 -1
- data/lib/pry/commands/ls/methods.rb +0 -3
- data/lib/pry/commands/ls/methods_helper.rb +1 -1
- data/lib/pry/commands/ls/self_methods.rb +2 -1
- data/lib/pry/commands/ls.rb +30 -31
- data/lib/pry/commands/play.rb +3 -4
- data/lib/pry/commands/pry_backtrace.rb +1 -1
- data/lib/pry/commands/raise_up.rb +2 -1
- data/lib/pry/commands/reload_code.rb +2 -2
- data/lib/pry/commands/ri.rb +9 -4
- data/lib/pry/commands/shell_command.rb +36 -9
- data/lib/pry/commands/shell_mode.rb +6 -6
- data/lib/pry/commands/show_doc.rb +5 -7
- data/lib/pry/commands/show_info.rb +41 -20
- data/lib/pry/commands/show_source.rb +5 -2
- data/lib/pry/commands/stat.rb +1 -1
- data/lib/pry/commands/watch_expression/expression.rb +1 -1
- data/lib/pry/commands/watch_expression.rb +9 -7
- data/lib/pry/commands/whereami.rb +16 -9
- data/lib/pry/commands/wtf.rb +15 -2
- data/lib/pry/config/behavior.rb +230 -114
- data/lib/pry/config/convenience.rb +24 -21
- data/lib/pry/config/default.rb +151 -153
- data/lib/pry/config/memoization.rb +48 -0
- data/lib/pry/config.rb +30 -19
- data/lib/pry/core_extensions.rb +15 -4
- data/lib/pry/editor.rb +5 -12
- data/lib/pry/exceptions.rb +1 -3
- data/lib/pry/forwardable.rb +23 -0
- data/lib/pry/helpers/base_helpers.rb +197 -110
- data/lib/pry/helpers/command_helpers.rb +5 -4
- data/lib/pry/helpers/documentation_helpers.rb +3 -2
- data/lib/pry/helpers/options_helpers.rb +6 -6
- data/lib/pry/helpers/platform.rb +58 -0
- data/lib/pry/helpers/table.rb +20 -15
- data/lib/pry/helpers/text.rb +82 -74
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/history.rb +44 -10
- data/lib/pry/hooks.rb +50 -109
- data/lib/pry/indent.rb +21 -19
- data/lib/pry/input_completer.rb +146 -123
- data/lib/pry/input_lock.rb +0 -2
- data/lib/pry/last_exception.rb +2 -2
- data/lib/pry/method/disowned.rb +3 -1
- data/lib/pry/method/patcher.rb +2 -5
- data/lib/pry/method/weird_method_locator.rb +21 -11
- data/lib/pry/method.rb +44 -38
- data/lib/pry/object_path.rb +5 -4
- data/lib/pry/output.rb +37 -37
- data/lib/pry/pager.rb +195 -181
- data/lib/pry/platform.rb +91 -0
- data/lib/pry/plugins.rb +27 -8
- data/lib/pry/prompt.rb +144 -25
- data/lib/pry/pry_class.rb +83 -33
- data/lib/pry/pry_instance.rb +94 -59
- data/lib/pry/repl.rb +70 -11
- data/lib/pry/repl_file_loader.rb +2 -3
- data/lib/pry/ring.rb +84 -0
- data/lib/pry/rubygem.rb +9 -7
- data/lib/pry/slop/LICENSE +20 -0
- data/lib/pry/slop/commands.rb +195 -0
- data/lib/pry/slop/option.rb +206 -0
- data/lib/pry/slop.rb +661 -0
- data/lib/pry/terminal.rb +18 -6
- data/lib/pry/testable/evalable.rb +15 -0
- data/lib/pry/testable/mockable.rb +14 -0
- data/lib/pry/testable/pry_tester.rb +73 -0
- data/lib/pry/testable/utility.rb +26 -0
- data/lib/pry/testable/variables.rb +46 -0
- data/lib/pry/testable.rb +70 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +9 -14
- data/lib/pry/wrapped_module.rb +22 -21
- data/lib/pry.rb +21 -50
- metadata +35 -46
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/simple_prompt.rb +0 -22
- data/lib/pry/history_array.rb +0 -121
- data/lib/pry/rbx_path.rb +0 -22
- data/lib/pry/test/helper.rb +0 -170
data/lib/pry/config/behavior.rb
CHANGED
@@ -1,139 +1,255 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
7
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
172
|
+
def last_default
|
173
|
+
last = @default
|
174
|
+
last = last.default while last and last.default
|
175
|
+
last
|
176
|
+
end
|
91
177
|
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
101
|
-
|
102
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
112
|
-
q.text inspect[1..-1].gsub(INSPECT_REGEXP, "default=<")
|
113
|
-
end
|
216
|
+
private
|
114
217
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
218
|
+
def __clip_inspect(obj)
|
219
|
+
"#{obj.class}:0x%x" % obj.object_id
|
220
|
+
end
|
119
221
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|