pry 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pry/commands.rb +66 -69
- data/lib/pry/version.rb +1 -1
- metadata +3 -3
data/lib/pry/commands.rb
CHANGED
@@ -25,7 +25,8 @@ class Pry
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
check_for_dynamically_defined_method = lambda do |
|
28
|
+
check_for_dynamically_defined_method = lambda do |meth|
|
29
|
+
file, _ = meth.source_location
|
29
30
|
if file =~ /(\(.*\))|<.*>/
|
30
31
|
raise "Cannot retrieve source for dynamically defined method."
|
31
32
|
end
|
@@ -36,6 +37,10 @@ class Pry
|
|
36
37
|
end
|
37
38
|
|
38
39
|
get_method_object = lambda do |meth_name, target, options|
|
40
|
+
if !meth_name
|
41
|
+
return nil
|
42
|
+
end
|
43
|
+
|
39
44
|
if options[:M]
|
40
45
|
target.eval("instance_method(:#{meth_name})")
|
41
46
|
elsif options[:m]
|
@@ -44,12 +49,17 @@ class Pry
|
|
44
49
|
begin
|
45
50
|
target.eval("instance_method(:#{meth_name})")
|
46
51
|
rescue
|
47
|
-
|
52
|
+
begin
|
53
|
+
target.eval("method(:#{meth_name})")
|
54
|
+
rescue
|
55
|
+
return nil
|
56
|
+
end
|
48
57
|
end
|
49
58
|
end
|
50
59
|
end
|
51
60
|
|
52
|
-
make_header = lambda do |
|
61
|
+
make_header = lambda do |meth, code_type|
|
62
|
+
file, line = meth.source_location
|
53
63
|
header = case code_type
|
54
64
|
when :ruby
|
55
65
|
"--\nFrom #{file} @ line #{line}:\n--"
|
@@ -58,6 +68,36 @@ class Pry
|
|
58
68
|
end
|
59
69
|
end
|
60
70
|
|
71
|
+
is_a_c_method = lambda do |meth|
|
72
|
+
meth.source_location.nil?
|
73
|
+
end
|
74
|
+
|
75
|
+
should_use_pry_doc = lambda do |meth|
|
76
|
+
Pry.has_pry_doc && is_a_c_method.call(meth)
|
77
|
+
end
|
78
|
+
|
79
|
+
code_type_for = lambda do |meth|
|
80
|
+
# only C methods
|
81
|
+
if should_use_pry_doc.call(meth)
|
82
|
+
info = Pry::MethodInfo.info_for(meth)
|
83
|
+
if info && info.source
|
84
|
+
code_type = :c
|
85
|
+
else
|
86
|
+
output.puts "Cannot find C method: #{meth.name}"
|
87
|
+
code_type = nil
|
88
|
+
end
|
89
|
+
else
|
90
|
+
if is_a_c_method.call(meth)
|
91
|
+
output.puts "Cannot locate this method: #{meth.name}. Try `gem install pry-doc` to get access to Ruby Core documentation."
|
92
|
+
code_type = nil
|
93
|
+
else
|
94
|
+
check_for_dynamically_defined_method.call(meth)
|
95
|
+
code_type = :ruby
|
96
|
+
end
|
97
|
+
end
|
98
|
+
code_type
|
99
|
+
end
|
100
|
+
|
61
101
|
command "!", "Clear the input buffer. Useful if the parsing process goes wrong and you get stuck in the read loop." do
|
62
102
|
output.puts "Input buffer cleared!"
|
63
103
|
opts[:eval_string].clear
|
@@ -459,44 +499,23 @@ e.g show-doc hello_method
|
|
459
499
|
|
460
500
|
next if options[:h]
|
461
501
|
|
462
|
-
if
|
463
|
-
output.puts "You need to specify a method. Type `show-doc --help` for help"
|
464
|
-
next
|
465
|
-
end
|
466
|
-
|
467
|
-
begin
|
468
|
-
meth = get_method_object.call(meth_name, target, options)
|
469
|
-
rescue
|
502
|
+
if (meth = get_method_object.call(meth_name, target, options)).nil?
|
470
503
|
output.puts "Invalid method name: #{meth_name}. Type `show-doc --help` for help"
|
471
504
|
next
|
472
505
|
end
|
473
506
|
|
474
|
-
code_type =
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
doc = info.docstring
|
482
|
-
code_type = info.source_type
|
483
|
-
else
|
484
|
-
begin
|
485
|
-
doc = meth.comment
|
486
|
-
rescue
|
487
|
-
output.puts "Cannot locate source for this method: #{meth_name}. Try `gem install pry-doc` to get access to Ruby Core documentation."
|
488
|
-
next
|
489
|
-
end
|
507
|
+
case code_type = code_type_for.call(meth)
|
508
|
+
when nil
|
509
|
+
next
|
510
|
+
when :c
|
511
|
+
doc = Pry::MethodInfo.info_for(meth).docstring
|
512
|
+
when :ruby
|
513
|
+
doc = meth.comment
|
490
514
|
doc = strip_leading_hash_from_ruby_comments.call(doc)
|
491
515
|
end
|
492
516
|
|
493
517
|
doc = process_comment_markup.call(doc, code_type)
|
494
|
-
|
495
|
-
file, line = meth.source_location
|
496
|
-
check_for_dynamically_defined_method.call(file)
|
497
|
-
|
498
|
-
output.puts make_header.call(file, line, code_type)
|
499
|
-
|
518
|
+
output.puts make_header.call(meth, code_type)
|
500
519
|
output.puts doc
|
501
520
|
doc
|
502
521
|
end
|
@@ -505,7 +524,7 @@ e.g show-doc hello_method
|
|
505
524
|
code.sub /\A\s*\/\*.*?\*\/\s*/m, ''
|
506
525
|
end
|
507
526
|
|
508
|
-
command "show-method", "Show the source for METH. Type `show-method --help` for more info." do |*args|
|
527
|
+
command "show-method", "Show the source for METH. Type `show-method --help` for more info. Aliases: show-source" do |*args|
|
509
528
|
options = {}
|
510
529
|
target = target()
|
511
530
|
meth_name = nil
|
@@ -538,46 +557,22 @@ e.g: show-method hello_method
|
|
538
557
|
|
539
558
|
next if options[:h]
|
540
559
|
|
541
|
-
|
542
|
-
meth_name = meth_name_from_binding.call(target) if !meth_name
|
543
|
-
if !meth_name
|
544
|
-
output.puts "You need to specify a method. Type `show-method --help` for help"
|
545
|
-
next
|
546
|
-
end
|
547
|
-
|
548
|
-
begin
|
549
|
-
meth = get_method_object.call(meth_name, target, options)
|
550
|
-
rescue
|
560
|
+
if (meth = get_method_object.call(meth_name, target, options)).nil?
|
551
561
|
output.puts "Invalid method name: #{meth_name}. Type `show-method --help` for help"
|
552
562
|
next
|
553
563
|
end
|
554
|
-
|
555
|
-
code_type =
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
if !info || !info.source
|
561
|
-
output.puts "Cannot find source for C method: #{meth_name}"
|
562
|
-
next
|
563
|
-
end
|
564
|
-
code = info.source
|
564
|
+
|
565
|
+
case code_type = code_type_for.call(meth)
|
566
|
+
when nil
|
567
|
+
next
|
568
|
+
when :c
|
569
|
+
code = Pry::MethodInfo.info_for(meth).source
|
565
570
|
code = strip_comments_from_c_code.call(code)
|
566
|
-
|
567
|
-
|
568
|
-
begin
|
569
|
-
code = meth.source
|
570
|
-
rescue
|
571
|
-
output.puts "Cannot locate source for this method: #{meth_name}. Try `gem install pry-doc` to get access to Ruby Core documentation."
|
572
|
-
next
|
573
|
-
end
|
571
|
+
when :ruby
|
572
|
+
code = meth.source
|
574
573
|
end
|
575
|
-
|
576
|
-
file, line = meth.source_location
|
577
|
-
check_for_dynamically_defined_method.call(file)
|
578
|
-
|
579
|
-
output.puts make_header.call(file, line, code_type)
|
580
574
|
|
575
|
+
output.puts make_header.call(meth, code_type)
|
581
576
|
if Pry.color
|
582
577
|
code = CodeRay.scan(code, code_type).term
|
583
578
|
end
|
@@ -585,6 +580,8 @@ e.g: show-method hello_method
|
|
585
580
|
output.puts code
|
586
581
|
code
|
587
582
|
end
|
583
|
+
|
584
|
+
alias_command "show-source", "show-method", ""
|
588
585
|
|
589
586
|
command "show-command", "Show sourcecode for a Pry command, e.g: show-command cd" do |command_name|
|
590
587
|
if !command_name
|
@@ -597,7 +594,7 @@ e.g: show-method hello_method
|
|
597
594
|
|
598
595
|
code = meth.source
|
599
596
|
file, line = meth.source_location
|
600
|
-
check_for_dynamically_defined_method.call(
|
597
|
+
check_for_dynamically_defined_method.call(meth)
|
601
598
|
|
602
599
|
output.puts "--\nFrom #{file} @ line #{line}:\n--"
|
603
600
|
|
data/lib/pry/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 7
|
8
|
-
-
|
9
|
-
version: 0.7.
|
8
|
+
- 3
|
9
|
+
version: 0.7.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Mair (banisterfiend)
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-22 00:00:00 +13:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|