pry 0.10.4 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +52 -18
- data/LICENSE +1 -1
- data/README.md +32 -31
- data/bin/pry +3 -7
- data/lib/pry/basic_object.rb +6 -0
- data/lib/pry/cli.rb +39 -34
- data/lib/pry/code/code_file.rb +8 -2
- data/lib/pry/code.rb +6 -1
- data/lib/pry/code_object.rb +23 -0
- data/lib/pry/color_printer.rb +20 -11
- data/lib/pry/command.rb +40 -16
- data/lib/pry/command_set.rb +9 -2
- data/lib/pry/commands/cat/exception_formatter.rb +11 -10
- data/lib/pry/commands/cat/file_formatter.rb +7 -3
- data/lib/pry/commands/code_collector.rb +16 -14
- data/lib/pry/commands/easter_eggs.rb +9 -9
- data/lib/pry/commands/edit/file_and_line_locator.rb +1 -1
- data/lib/pry/commands/edit.rb +7 -3
- data/lib/pry/commands/find_method.rb +1 -1
- data/lib/pry/commands/gem_open.rb +1 -1
- data/lib/pry/commands/gem_readme.rb +25 -0
- data/lib/pry/commands/gem_search.rb +40 -0
- data/lib/pry/commands/hist.rb +2 -2
- data/lib/pry/commands/jump_to.rb +7 -7
- data/lib/pry/commands/ls/constants.rb +12 -1
- data/lib/pry/commands/ls/formatter.rb +1 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +2 -2
- data/lib/pry/commands/ls/self_methods.rb +2 -0
- data/lib/pry/commands/ls.rb +3 -1
- data/lib/pry/commands/play.rb +2 -2
- data/lib/pry/commands/reload_code.rb +2 -2
- data/lib/pry/commands/ri.rb +4 -0
- data/lib/pry/commands/shell_command.rb +34 -8
- data/lib/pry/commands/show_info.rb +10 -2
- data/lib/pry/commands/watch_expression/expression.rb +1 -1
- data/lib/pry/commands/whereami.rb +7 -6
- data/lib/pry/config/behavior.rb +140 -49
- data/lib/pry/config/default.rb +21 -33
- data/lib/pry/config/memoization.rb +44 -0
- data/lib/pry/config.rb +3 -16
- data/lib/pry/core_extensions.rb +12 -2
- data/lib/pry/editor.rb +1 -1
- data/lib/pry/exceptions.rb +1 -1
- data/lib/pry/forwardable.rb +23 -0
- data/lib/pry/helpers/base_helpers.rb +6 -10
- data/lib/pry/helpers/documentation_helpers.rb +1 -0
- data/lib/pry/helpers/options_helpers.rb +1 -1
- data/lib/pry/helpers/text.rb +69 -75
- data/lib/pry/history.rb +22 -1
- data/lib/pry/history_array.rb +1 -1
- data/lib/pry/hooks.rb +48 -107
- data/lib/pry/indent.rb +6 -2
- data/lib/pry/input_completer.rb +138 -120
- data/lib/pry/last_exception.rb +2 -2
- data/lib/pry/method/disowned.rb +1 -0
- data/lib/pry/method/patcher.rb +0 -3
- data/lib/pry/method.rb +15 -15
- data/lib/pry/output.rb +37 -38
- data/lib/pry/pager.rb +11 -8
- data/lib/pry/plugins.rb +20 -5
- data/lib/pry/pry_class.rb +30 -4
- data/lib/pry/pry_instance.rb +8 -6
- data/lib/pry/repl.rb +38 -8
- data/lib/pry/repl_file_loader.rb +1 -1
- data/lib/pry/rubygem.rb +3 -1
- data/lib/pry/slop/LICENSE +20 -0
- data/lib/pry/slop/commands.rb +196 -0
- data/lib/pry/slop/option.rb +208 -0
- data/lib/pry/slop.rb +661 -0
- data/lib/pry/terminal.rb +16 -5
- data/lib/pry/test/helper.rb +12 -3
- data/lib/pry/version.rb +1 -1
- data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +7 -13
- data/lib/pry/wrapped_module.rb +7 -7
- data/lib/pry.rb +4 -4
- metadata +14 -19
data/lib/pry/command.rb
CHANGED
|
@@ -52,7 +52,7 @@ class Pry
|
|
|
52
52
|
# Define or get the command's banner
|
|
53
53
|
def banner(arg=nil)
|
|
54
54
|
@banner = arg if arg
|
|
55
|
-
@banner
|
|
55
|
+
@banner ||= description
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
def block
|
|
@@ -167,11 +167,12 @@ class Pry
|
|
|
167
167
|
end
|
|
168
168
|
end
|
|
169
169
|
|
|
170
|
+
# @deprecated Replaced with {Pry::Hooks#add_hook}. Left for compatibility.
|
|
170
171
|
# Store hooks to be run before or after the command body.
|
|
171
172
|
# @see {Pry::CommandSet#before_command}
|
|
172
173
|
# @see {Pry::CommandSet#after_command}
|
|
173
174
|
def hooks
|
|
174
|
-
|
|
175
|
+
Pry.hooks
|
|
175
176
|
end
|
|
176
177
|
|
|
177
178
|
def command_regex
|
|
@@ -223,6 +224,7 @@ class Pry
|
|
|
223
224
|
attr_accessor :arg_string
|
|
224
225
|
attr_accessor :context
|
|
225
226
|
attr_accessor :command_set
|
|
227
|
+
attr_accessor :hooks
|
|
226
228
|
attr_accessor :_pry_
|
|
227
229
|
|
|
228
230
|
# The block we pass *into* a command so long as `:takes_block` is
|
|
@@ -271,6 +273,7 @@ class Pry
|
|
|
271
273
|
self.output = context[:output]
|
|
272
274
|
self.eval_string = context[:eval_string]
|
|
273
275
|
self.command_set = context[:command_set]
|
|
276
|
+
self.hooks = context[:hooks]
|
|
274
277
|
self._pry_ = context[:pry_instance]
|
|
275
278
|
end
|
|
276
279
|
|
|
@@ -424,10 +427,20 @@ class Pry
|
|
|
424
427
|
raise CommandError, "The command '#{command_name}' requires an argument."
|
|
425
428
|
end
|
|
426
429
|
|
|
427
|
-
ret =
|
|
430
|
+
ret = use_unpatched_symbol do
|
|
431
|
+
call_with_hooks(*args)
|
|
432
|
+
end
|
|
428
433
|
command_options[:keep_retval] ? ret : void
|
|
429
434
|
end
|
|
430
435
|
|
|
436
|
+
def use_unpatched_symbol
|
|
437
|
+
call_method = Symbol.method_defined?(:call) && Symbol.instance_method(:call)
|
|
438
|
+
Symbol.class_eval { undef :call } if call_method
|
|
439
|
+
yield
|
|
440
|
+
ensure
|
|
441
|
+
Symbol.instance_eval { define_method(:call, call_method) } if call_method
|
|
442
|
+
end
|
|
443
|
+
|
|
431
444
|
# Are all the gems required to use this command installed?
|
|
432
445
|
#
|
|
433
446
|
# @return Boolean
|
|
@@ -445,17 +458,28 @@ class Pry
|
|
|
445
458
|
|
|
446
459
|
private
|
|
447
460
|
|
|
461
|
+
def find_hooks(event)
|
|
462
|
+
event_name = "#{event}_#{command_name}"
|
|
463
|
+
(self.hooks || self.class.hooks).get_hooks(event_name).values
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
def before_hooks
|
|
467
|
+
find_hooks('before')
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
def after_hooks
|
|
471
|
+
find_hooks('after')
|
|
472
|
+
end
|
|
473
|
+
|
|
448
474
|
# Run the `#call` method and all the registered hooks.
|
|
449
475
|
# @param [Array<String>] args The arguments to `#call`
|
|
450
476
|
# @return [Object] The return value from `#call`
|
|
451
477
|
def call_with_hooks(*args)
|
|
452
|
-
|
|
453
|
-
instance_exec(*args, &block)
|
|
454
|
-
end
|
|
478
|
+
before_hooks.each { |block| instance_exec(*args, &block) }
|
|
455
479
|
|
|
456
480
|
ret = call(*args)
|
|
457
481
|
|
|
458
|
-
|
|
482
|
+
after_hooks.each do |block|
|
|
459
483
|
ret = instance_exec(*args, &block)
|
|
460
484
|
end
|
|
461
485
|
|
|
@@ -507,7 +531,7 @@ class Pry
|
|
|
507
531
|
# subclasses.
|
|
508
532
|
#
|
|
509
533
|
# Create subclasses using {Pry::CommandSet#create_command}, and override the
|
|
510
|
-
# `options(opt)` method to set up an instance of Slop, and the `process`
|
|
534
|
+
# `options(opt)` method to set up an instance of Pry::Slop, and the `process`
|
|
511
535
|
# method to actually run the command. If necessary, you can also override
|
|
512
536
|
# `setup` which will be called before `options`, for example to require any
|
|
513
537
|
# gems your command needs to run, or to set up state.
|
|
@@ -583,15 +607,15 @@ class Pry
|
|
|
583
607
|
end
|
|
584
608
|
end
|
|
585
609
|
|
|
586
|
-
# Return the help generated by Slop for this command.
|
|
610
|
+
# Return the help generated by Pry::Slop for this command.
|
|
587
611
|
def help
|
|
588
612
|
slop.help
|
|
589
613
|
end
|
|
590
614
|
|
|
591
|
-
# Return an instance of Slop that can parse either subcommands or the
|
|
615
|
+
# Return an instance of Pry::Slop that can parse either subcommands or the
|
|
592
616
|
# options that this command accepts.
|
|
593
617
|
def slop
|
|
594
|
-
Slop.new do |opt|
|
|
618
|
+
Pry::Slop.new do |opt|
|
|
595
619
|
opt.banner(unindent(self.class.banner))
|
|
596
620
|
subcommands(opt)
|
|
597
621
|
options(opt)
|
|
@@ -603,9 +627,9 @@ class Pry
|
|
|
603
627
|
# @param [String] search The line typed so far
|
|
604
628
|
# @return [Array<String>] the words to complete
|
|
605
629
|
def complete(search)
|
|
606
|
-
slop.
|
|
630
|
+
slop.flat_map do |opt|
|
|
607
631
|
[opt.long && "--#{opt.long} " || opt.short && "-#{opt.short}"]
|
|
608
|
-
end.
|
|
632
|
+
end.compact + super
|
|
609
633
|
end
|
|
610
634
|
|
|
611
635
|
# A method called just before `options(opt)` as part of `call`.
|
|
@@ -620,7 +644,7 @@ class Pry
|
|
|
620
644
|
# end
|
|
621
645
|
def setup; end
|
|
622
646
|
|
|
623
|
-
# A method to setup Slop commands so it can parse the subcommands your
|
|
647
|
+
# A method to setup Pry::Slop commands so it can parse the subcommands your
|
|
624
648
|
# command expects. If you need to set up default values, use `setup`
|
|
625
649
|
# instead.
|
|
626
650
|
#
|
|
@@ -655,7 +679,7 @@ class Pry
|
|
|
655
679
|
# end
|
|
656
680
|
def subcommands(cmd); end
|
|
657
681
|
|
|
658
|
-
# A method to setup Slop so it can parse the options your command expects.
|
|
682
|
+
# A method to setup Pry::Slop so it can parse the options your command expects.
|
|
659
683
|
#
|
|
660
684
|
# @note Please don't do anything side-effecty in the main part of this
|
|
661
685
|
# method, as it may be called by Pry at any time for introspection reasons.
|
|
@@ -672,7 +696,7 @@ class Pry
|
|
|
672
696
|
|
|
673
697
|
# The actual body of your command should go here.
|
|
674
698
|
#
|
|
675
|
-
# The `opts` mehod can be called to get the options that Slop has passed,
|
|
699
|
+
# The `opts` mehod can be called to get the options that Pry::Slop has passed,
|
|
676
700
|
# and `args` gives the remaining, unparsed arguments.
|
|
677
701
|
#
|
|
678
702
|
# The return value of this method is discarded unless the command was
|
data/lib/pry/command_set.rb
CHANGED
|
@@ -125,9 +125,10 @@ class Pry
|
|
|
125
125
|
# Pry.config.commands.before_command("whereami") do |n|
|
|
126
126
|
# output.puts "parameter passed was #{n}"
|
|
127
127
|
# end
|
|
128
|
+
# @deprecated Use {Pry::Hooks#add_hook} instead.
|
|
128
129
|
def before_command(search, &block)
|
|
129
130
|
cmd = find_command_by_match_or_listing(search)
|
|
130
|
-
cmd.hooks
|
|
131
|
+
cmd.hooks.add_hook("before_#{cmd.command_name}", random_hook_name, block)
|
|
131
132
|
end
|
|
132
133
|
|
|
133
134
|
# Execute a block of code after a command is invoked. The block also
|
|
@@ -139,11 +140,17 @@ class Pry
|
|
|
139
140
|
# Pry.config.commands.after_command("whereami") do |n|
|
|
140
141
|
# output.puts "command complete!"
|
|
141
142
|
# end
|
|
143
|
+
# @deprecated Use {Pry::Hooks#add_hook} instead.
|
|
142
144
|
def after_command(search, &block)
|
|
143
145
|
cmd = find_command_by_match_or_listing(search)
|
|
144
|
-
cmd.hooks
|
|
146
|
+
cmd.hooks.add_hook("after_#{cmd.command_name}", random_hook_name, block)
|
|
145
147
|
end
|
|
146
148
|
|
|
149
|
+
def random_hook_name
|
|
150
|
+
(0...8).map { ('a'..'z').to_a[rand(26)] }.join
|
|
151
|
+
end
|
|
152
|
+
private :random_hook_name
|
|
153
|
+
|
|
147
154
|
def each(&block)
|
|
148
155
|
@commands.each(&block)
|
|
149
156
|
end
|
|
@@ -27,16 +27,17 @@ class Pry
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def backtrace_level
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
@backtrace_level ||=
|
|
31
|
+
begin
|
|
32
|
+
bl = if opts[:ex].nil?
|
|
33
|
+
ex.bt_index
|
|
34
|
+
else
|
|
35
|
+
ex.bt_index = absolute_index_number(opts[:ex], ex.backtrace.size)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
increment_backtrace_level
|
|
39
|
+
bl
|
|
40
|
+
end
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
def increment_backtrace_level
|
|
@@ -6,6 +6,8 @@ class Pry
|
|
|
6
6
|
attr_reader :_pry_
|
|
7
7
|
|
|
8
8
|
def initialize(file_with_embedded_line, _pry_, opts)
|
|
9
|
+
raise CommandError, "Must provide a filename, --in, or --ex." if !file_with_embedded_line
|
|
10
|
+
|
|
9
11
|
@file_with_embedded_line = file_with_embedded_line
|
|
10
12
|
@opts = opts
|
|
11
13
|
@_pry_ = _pry_
|
|
@@ -13,8 +15,6 @@ class Pry
|
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def format
|
|
16
|
-
raise CommandError, "Must provide a filename, --in, or --ex." if !file_with_embedded_line
|
|
17
|
-
|
|
18
18
|
set_file_and_dir_locals(file_name, _pry_, _pry_.current_context)
|
|
19
19
|
decorate(@code_from_file)
|
|
20
20
|
end
|
|
@@ -40,7 +40,11 @@ class Pry
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def decorate(content)
|
|
43
|
-
|
|
43
|
+
if line_number
|
|
44
|
+
super(content.around(line_number, code_window_size))
|
|
45
|
+
else
|
|
46
|
+
super
|
|
47
|
+
end
|
|
44
48
|
end
|
|
45
49
|
|
|
46
50
|
def code_type
|
|
@@ -51,21 +51,23 @@ class Pry
|
|
|
51
51
|
#
|
|
52
52
|
# @return [String]
|
|
53
53
|
def content
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
@content ||=
|
|
55
|
+
begin
|
|
56
|
+
raise CommandError, "Only one of --out, --in, --doc and CODE_OBJECT may be specified." if bad_option_combination?
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
content = case
|
|
59
|
+
when opts.present?(:o)
|
|
60
|
+
pry_output_content
|
|
61
|
+
when opts.present?(:i)
|
|
62
|
+
pry_input_content
|
|
63
|
+
when opts.present?(:d)
|
|
64
|
+
code_object_doc
|
|
65
|
+
else
|
|
66
|
+
code_object_source_or_file
|
|
67
|
+
end
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
restrict_to_lines(content, line_range)
|
|
70
|
+
end
|
|
69
71
|
end
|
|
70
72
|
|
|
71
73
|
# The code object
|
|
@@ -141,7 +143,7 @@ class Pry
|
|
|
141
143
|
end
|
|
142
144
|
|
|
143
145
|
def file_content
|
|
144
|
-
if File.
|
|
146
|
+
if File.exist?(obj_name)
|
|
145
147
|
# Set the file accessor.
|
|
146
148
|
self.file = obj_name
|
|
147
149
|
File.read(obj_name)
|
|
@@ -10,17 +10,17 @@ class Pry
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
command "get-naked", "" do
|
|
13
|
-
|
|
13
|
+
txt = %{
|
|
14
14
|
--
|
|
15
15
|
We dont have to take our clothes off to have a good time.
|
|
16
16
|
We could dance & party all night And drink some cherry wine.
|
|
17
17
|
-- Jermaine Stewart }
|
|
18
|
-
output.puts
|
|
19
|
-
|
|
18
|
+
output.puts txt
|
|
19
|
+
txt
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
command "east-coker", "" do
|
|
23
|
-
|
|
23
|
+
txt = %{
|
|
24
24
|
--
|
|
25
25
|
Now the light falls
|
|
26
26
|
Across the open field, leaving the deep lane
|
|
@@ -34,12 +34,12 @@ class Pry
|
|
|
34
34
|
Wait for the early owl.
|
|
35
35
|
-- T.S Eliot
|
|
36
36
|
}
|
|
37
|
-
output.puts
|
|
38
|
-
|
|
37
|
+
output.puts txt
|
|
38
|
+
txt
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
command "cohen-poem", "" do
|
|
42
|
-
|
|
42
|
+
txt = %{
|
|
43
43
|
--
|
|
44
44
|
When this American woman,
|
|
45
45
|
whose thighs are bound in casual red cloth,
|
|
@@ -57,8 +57,8 @@ class Pry
|
|
|
57
57
|
they are lost for hours.
|
|
58
58
|
-- Leonard Cohen
|
|
59
59
|
}
|
|
60
|
-
output.puts
|
|
61
|
-
|
|
60
|
+
output.puts txt
|
|
61
|
+
txt
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
command "pessoa-poem", "" do
|
|
@@ -7,7 +7,7 @@ class Pry
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def from_code_object(code_object, filename_argument)
|
|
10
|
-
if File.
|
|
10
|
+
if File.exist?(code_object.source_file.to_s)
|
|
11
11
|
[code_object.source_file, code_object.source_line]
|
|
12
12
|
else
|
|
13
13
|
raise CommandError, "Cannot find a file for #{filename_argument}!"
|
data/lib/pry/commands/edit.rb
CHANGED
|
@@ -46,7 +46,7 @@ class Pry
|
|
|
46
46
|
# code defined in pry, eval'd within pry.
|
|
47
47
|
repl_edit
|
|
48
48
|
elsif runtime_patch?
|
|
49
|
-
# patch code without persisting changes
|
|
49
|
+
# patch code without persisting changes, implies future changes are patches
|
|
50
50
|
apply_runtime_patch
|
|
51
51
|
else
|
|
52
52
|
# code stored in actual files, eval'd at top-level
|
|
@@ -72,7 +72,7 @@ class Pry
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
def runtime_patch?
|
|
75
|
-
!file_based_exception? && (opts.present?(:patch) || pry_method?(code_object))
|
|
75
|
+
!file_based_exception? && (opts.present?(:patch) || previously_patched?(code_object) || pry_method?(code_object))
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
def apply_runtime_patch
|
|
@@ -140,6 +140,10 @@ class Pry
|
|
|
140
140
|
code_object.pry_method?
|
|
141
141
|
end
|
|
142
142
|
|
|
143
|
+
def previously_patched?(code_object)
|
|
144
|
+
code_object.is_a?(Pry::Method) && Pry::Method::Patcher.code_for(code_object.source_location.first)
|
|
145
|
+
end
|
|
146
|
+
|
|
143
147
|
def patch_exception?
|
|
144
148
|
opts.present?(:ex) && opts.present?(:patch)
|
|
145
149
|
end
|
|
@@ -153,7 +157,7 @@ class Pry
|
|
|
153
157
|
case opts[:i]
|
|
154
158
|
when Range
|
|
155
159
|
(_pry_.input_array[opts[:i]] || []).join
|
|
156
|
-
when
|
|
160
|
+
when Integer
|
|
157
161
|
_pry_.input_array[opts[:i]] || ""
|
|
158
162
|
else
|
|
159
163
|
raise Pry::CommandError, "Not a valid range: #{opts[:i]}"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class Pry::Command::GemReadme < Pry::ClassCommand
|
|
2
|
+
match 'gem-readme'
|
|
3
|
+
description 'Show the readme bundled with a rubygem'
|
|
4
|
+
group 'Gems'
|
|
5
|
+
command_options argument_required: true
|
|
6
|
+
banner <<-BANNER
|
|
7
|
+
gem-readme gem
|
|
8
|
+
Show the readme bundled with a rubygem
|
|
9
|
+
BANNER
|
|
10
|
+
|
|
11
|
+
def process(name)
|
|
12
|
+
spec = Gem::Specification.find_by_name(name)
|
|
13
|
+
glob = File.join(spec.full_gem_path, 'README*')
|
|
14
|
+
readme = Dir[glob][0]
|
|
15
|
+
if File.exist?(readme.to_s)
|
|
16
|
+
_pry_.pager.page File.read(readme)
|
|
17
|
+
else
|
|
18
|
+
raise Pry::CommandError, "Gem '#{name}' doesn't appear to have a README"
|
|
19
|
+
end
|
|
20
|
+
rescue Gem::LoadError
|
|
21
|
+
raise Pry::CommandError, "Gem '#{name}' wasn't found. Are you sure it is installed?"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
Pry::Commands.add_command(self)
|
|
25
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
class Pry::Command::GemSearch < Pry::ClassCommand
|
|
2
|
+
match 'gem-search'
|
|
3
|
+
description 'Search for a gem with the rubygems.org JSON API'
|
|
4
|
+
group 'Gems'
|
|
5
|
+
command_options argument_required: true
|
|
6
|
+
banner <<-BANNER
|
|
7
|
+
gem-search [options] gem
|
|
8
|
+
Search for a gem with the rubygems.org HTTP API
|
|
9
|
+
BANNER
|
|
10
|
+
|
|
11
|
+
API_ENDPOINT = 'https://rubygems.org/api/v1/search.json'
|
|
12
|
+
|
|
13
|
+
def setup
|
|
14
|
+
require 'json' unless defined?(JSON)
|
|
15
|
+
require 'net/http' unless defined?(Net::HTTP)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def options(opt)
|
|
19
|
+
opt.on :l, :limit, 'Limit the number of results (max: 30)',
|
|
20
|
+
default: 10,
|
|
21
|
+
as: Integer,
|
|
22
|
+
argument: true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def process(str)
|
|
26
|
+
uri = URI.parse(API_ENDPOINT)
|
|
27
|
+
uri.query = URI.encode_www_form(query: str)
|
|
28
|
+
gems = JSON.load Net::HTTP.get(uri)
|
|
29
|
+
_pry_.pager.page list_as_string(gems, opts[:limit])
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
def list_as_string(gems, limit = 10)
|
|
34
|
+
gems[0..limit-1].map do |gem|
|
|
35
|
+
name, version, info = gem.values_at 'name', 'version', 'info'
|
|
36
|
+
"#{text.bold(name)} #{text.bold('v'+version)} \n#{info}\n\n"
|
|
37
|
+
end.join
|
|
38
|
+
end
|
|
39
|
+
Pry::Commands.add_command(self)
|
|
40
|
+
end
|
data/lib/pry/commands/hist.rb
CHANGED
data/lib/pry/commands/jump_to.rb
CHANGED
|
@@ -9,18 +9,18 @@ class Pry
|
|
|
9
9
|
BANNER
|
|
10
10
|
|
|
11
11
|
def process(break_level)
|
|
12
|
-
break_level
|
|
13
|
-
nesting_level
|
|
12
|
+
break_level = break_level.to_i
|
|
13
|
+
nesting_level = _pry_.binding_stack.size - 1
|
|
14
|
+
max_nest_level = nesting_level - 1
|
|
14
15
|
|
|
15
16
|
case break_level
|
|
16
17
|
when nesting_level
|
|
17
18
|
output.puts "Already at nesting level #{nesting_level}"
|
|
18
|
-
when
|
|
19
|
-
_pry_.binding_stack
|
|
20
|
-
|
|
19
|
+
when 0..max_nest_level
|
|
20
|
+
_pry_.binding_stack = _pry_.binding_stack[0..break_level]
|
|
21
21
|
else
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
output.puts "Invalid nest level. Must be between 0 and " \
|
|
23
|
+
"#{max_nest_level}. Got #{break_level}."
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -3,15 +3,17 @@ require 'pry/commands/ls/interrogatable'
|
|
|
3
3
|
class Pry
|
|
4
4
|
class Command::Ls < Pry::ClassCommand
|
|
5
5
|
class Constants < Pry::Command::Ls::Formatter
|
|
6
|
+
DEPRECATED_CONSTANTS = [:Fixnum, :Bignum, :TimeoutError, :NIL, :FALSE, :TRUE]
|
|
7
|
+
DEPRECATED_CONSTANTS << :JavaPackageModuleTemplate if Pry::Helpers::BaseHelpers.jruby?
|
|
6
8
|
include Pry::Command::Ls::Interrogatable
|
|
7
9
|
|
|
8
|
-
|
|
9
10
|
def initialize(interrogatee, no_user_opts, opts, _pry_)
|
|
10
11
|
super(_pry_)
|
|
11
12
|
@interrogatee = interrogatee
|
|
12
13
|
@no_user_opts = no_user_opts
|
|
13
14
|
@default_switch = opts[:constants]
|
|
14
15
|
@verbose_switch = opts[:verbose]
|
|
16
|
+
@dconstants = opts.dconstants?
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def correct_opts?
|
|
@@ -26,8 +28,17 @@ class Pry
|
|
|
26
28
|
|
|
27
29
|
private
|
|
28
30
|
|
|
31
|
+
def show_deprecated_constants?
|
|
32
|
+
@dconstants == true
|
|
33
|
+
end
|
|
34
|
+
|
|
29
35
|
def format(mod, constants)
|
|
30
36
|
constants.sort_by(&:downcase).map do |name|
|
|
37
|
+
if Object.respond_to?(:deprecate_constant) and
|
|
38
|
+
DEPRECATED_CONSTANTS.include?(name) and
|
|
39
|
+
!show_deprecated_constants?
|
|
40
|
+
next
|
|
41
|
+
end
|
|
31
42
|
if const = (!mod.autoload?(name) && (mod.const_get(name) || true) rescue nil)
|
|
32
43
|
if (const < Exception rescue false)
|
|
33
44
|
color(:exception_constant, name)
|
|
@@ -19,7 +19,7 @@ module Pry::Command::Ls::JRubyHacks
|
|
|
19
19
|
m.name.sub(/\A(is|get|set)(?=[A-Z_])/, '').gsub(/[_?=]/, '').downcase
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
grouped.
|
|
22
|
+
grouped.flat_map do |key, values|
|
|
23
23
|
values = values.sort_by do |m|
|
|
24
24
|
rubbishness(m.name)
|
|
25
25
|
end
|
|
@@ -28,7 +28,7 @@ module Pry::Command::Ls::JRubyHacks
|
|
|
28
28
|
values.select do |x|
|
|
29
29
|
(!found.any? { |y| x == y }) && found << x
|
|
30
30
|
end
|
|
31
|
-
end
|
|
31
|
+
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
# When removing jruby aliases, we want to keep the alias that is
|
data/lib/pry/commands/ls.rb
CHANGED
|
@@ -61,7 +61,9 @@ class Pry
|
|
|
61
61
|
" " * 32 << "Constants that are pending autoload? are also shown (in yellow)"
|
|
62
62
|
opt.on :i, :ivars, "Show instance variables (in blue) and class variables (in bright blue)"
|
|
63
63
|
opt.on :G, :grep, "Filter output by regular expression", :argument => true
|
|
64
|
-
|
|
64
|
+
if Object.respond_to?(:deprecate_constant)
|
|
65
|
+
opt.on :d, :dconstants, "Show deprecated constants"
|
|
66
|
+
end
|
|
65
67
|
if jruby?
|
|
66
68
|
opt.on :J, "all-java", "Show all the aliases for methods from java (default is to show only prettiest)"
|
|
67
69
|
end
|
data/lib/pry/commands/play.rb
CHANGED
|
@@ -12,7 +12,7 @@ class Pry
|
|
|
12
12
|
|
|
13
13
|
play --lines 149..153 # assumes current context
|
|
14
14
|
play -i 20 --lines 1..3 # assumes lines of the input expression at 20
|
|
15
|
-
play -o 4 # the output of
|
|
15
|
+
play -o 4 # the output of an expression at 4
|
|
16
16
|
play Pry#repl -l 1..-1 # play the contents of Pry#repl method
|
|
17
17
|
play -e 2 # play from specified line until end of valid expression
|
|
18
18
|
play hello.rb # play a file
|
|
@@ -91,7 +91,7 @@ class Pry
|
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
def file_content
|
|
94
|
-
if default_file && File.
|
|
94
|
+
if default_file && File.exist?(default_file)
|
|
95
95
|
@cc.restrict_to_lines(File.read(default_file), @cc.line_range)
|
|
96
96
|
else
|
|
97
97
|
raise CommandError, "File does not exist! File was: #{default_file.inspect}"
|
|
@@ -31,7 +31,7 @@ class Pry
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def reload_current_file
|
|
34
|
-
if !File.
|
|
34
|
+
if !File.exist?(current_file)
|
|
35
35
|
raise CommandError, "Current file: #{current_file} cannot be found on disk!"
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -49,7 +49,7 @@ class Pry
|
|
|
49
49
|
def check_for_reloadability(code_object, identifier)
|
|
50
50
|
if !code_object || !code_object.source_file
|
|
51
51
|
raise CommandError, "Cannot locate #{identifier}!"
|
|
52
|
-
elsif !File.
|
|
52
|
+
elsif !File.exist?(code_object.source_file)
|
|
53
53
|
raise CommandError,
|
|
54
54
|
"Cannot reload #{identifier} as it has no associated file on disk. " \
|
|
55
55
|
"File found was: #{code_object.source_file}"
|