ri_for 0.4.1 → 0.5.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.
- data/VERSION +1 -1
- data/lib/ri_for.rb +1 -1
- data/lib/ri_for/class_desc.rb +2 -0
- data/lib/ri_for/method_ri.rb +28 -27
- data/test/test_method.rb +5 -6
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/lib/ri_for.rb
CHANGED
data/lib/ri_for/class_desc.rb
CHANGED
data/lib/ri_for/method_ri.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rdoc'
|
3
|
-
require 'rdoc/ri/driver'
|
4
1
|
require 'sane'
|
5
2
|
|
6
3
|
if RUBY_VERSION < '1.9'
|
4
|
+
require 'rubygems'
|
7
5
|
require 'ruby2ruby'
|
8
6
|
require 'parse_tree'
|
9
7
|
gem 'rdp-arguments' # TODO why is this necessary?
|
@@ -55,17 +53,16 @@ module SourceLocationDesc
|
|
55
53
|
string =~ /Method: .*([#\.])(.*)>/ # include the # or .
|
56
54
|
joiner = $1
|
57
55
|
method_name = $2
|
58
|
-
|
59
|
-
sig = "sig: #{full_name} arity: #{arity}"
|
56
|
+
sig = "sig: #{class_name}#{joiner}#{method_name} arity #{arity}"
|
60
57
|
doc << sig
|
61
58
|
param_string = sig
|
62
|
-
|
59
|
+
|
63
60
|
# now gather up any other information we now about it, in case there are no rdocs, so we can see it early...
|
64
61
|
|
65
62
|
if !(respond_to? :source_location)
|
66
63
|
# pull out names for 1.8
|
67
64
|
begin
|
68
|
-
|
65
|
+
klass = eval(class_name)
|
69
66
|
# we don't call to_ruby to overcome ruby2ruby bug http://rubyforge.org/tracker/index.php?func=detail&aid=26891&group_id=1513&atid=5921
|
70
67
|
if joiner == '#'
|
71
68
|
raw_code = ParseTree.new.parse_tree_for_method(klass, method_name)
|
@@ -73,7 +70,7 @@ module SourceLocationDesc
|
|
73
70
|
raw_code = ParseTree.new.parse_tree_for_method(klass.singleton_class, method_name)
|
74
71
|
end
|
75
72
|
doc << Ruby2Ruby.new.process(ParseTree.new.process(raw_code))
|
76
|
-
|
73
|
+
|
77
74
|
args = Arguments.names(klass, method_name, false) rescue Arguments.names(klass.singleton_class, method_name, false)
|
78
75
|
out = []
|
79
76
|
args.each{|arg_pair|
|
@@ -82,11 +79,11 @@ module SourceLocationDesc
|
|
82
79
|
out = out.join(', ')
|
83
80
|
return out if want_just_summary
|
84
81
|
|
85
|
-
param_string = "Parameters: #{method_name}(" + out + ")"
|
82
|
+
param_string = "Parameters: #{method_name}(" + out + ")"
|
86
83
|
doc << param_string unless want_the_description_returned
|
87
84
|
rescue Exception => e
|
88
85
|
doc << "appears to be a c method"
|
89
|
-
puts "fail to parse tree: #{class_name} #{e} #{e.backtrace}" if $
|
86
|
+
puts "fail to parse tree: #{class_name} #{e} #{e.backtrace}" if $DEBUG
|
90
87
|
doc << "appears to be a c method"
|
91
88
|
end
|
92
89
|
else
|
@@ -128,48 +125,52 @@ module SourceLocationDesc
|
|
128
125
|
end
|
129
126
|
end
|
130
127
|
|
131
|
-
puts doc
|
128
|
+
puts doc unless want_the_description_returned
|
132
129
|
|
130
|
+
unless (already_got_ri || want_just_summary)
|
131
|
+
require 'rdoc'
|
132
|
+
require 'rdoc/ri/driver'
|
133
133
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
134
|
+
# show default RI for it
|
135
|
+
begin
|
136
|
+
pps 'Searching ri for', sig, '...'
|
137
|
+
RDoc::RI::Driver.run [full_name, '--no-pager']
|
138
|
+
rescue *[StandardError, SystemExit]
|
139
|
+
# not found
|
140
|
+
ensure
|
141
|
+
puts '(end ri)'
|
142
|
+
end
|
143
|
+
end
|
143
144
|
|
144
145
|
if want_the_description_returned # give them something they can examine
|
145
146
|
doc
|
146
147
|
else
|
147
|
-
param_string # one liner
|
148
|
+
param_string.strip # return one liner
|
148
149
|
end
|
149
|
-
end
|
150
150
|
|
151
|
+
end
|
152
|
+
|
151
153
|
alias :desc :ri
|
154
|
+
|
152
155
|
end
|
153
156
|
|
154
157
|
class Method; include SourceLocationDesc; end
|
155
158
|
class UnboundMethod; include SourceLocationDesc; end
|
156
159
|
|
157
160
|
# TODO mixin from a separate module
|
161
|
+
|
158
162
|
class Object
|
159
163
|
# currently rather verbose, but will attempt to describe all it knows about a method
|
160
164
|
def ri_for name, options = {}
|
161
165
|
if self.is_a?(Class) || self.is_a?(Module)
|
162
166
|
# i.e. String.strip
|
163
167
|
begin
|
164
|
-
instance_method(name).ri(options)
|
168
|
+
instance_method(name).ri(options)
|
165
169
|
rescue NameError => e #allow for Class.instance_method_name, Module.instance_method_name
|
166
|
-
method(name).ri(options)
|
170
|
+
method(name).ri(options)
|
167
171
|
end
|
168
172
|
else
|
169
173
|
method(name).desc(options)
|
170
174
|
end
|
171
175
|
end
|
172
176
|
end
|
173
|
-
|
174
|
-
# attribution
|
175
|
-
# originally gleaned from http://p.ramaze.net/17901
|
data/test/test_method.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'ffi'
|
3
3
|
|
4
|
-
$VERBOSE = true
|
5
|
-
|
6
4
|
class A
|
7
5
|
# a suh-weet rdoc
|
8
6
|
def go(a=5)
|
@@ -16,7 +14,6 @@ end
|
|
16
14
|
|
17
15
|
=begin
|
18
16
|
doctest_require: '../lib/ri_for'
|
19
|
-
>> $VERBOSE = true
|
20
17
|
>> output = A.ri_for(:go, :want_the_description_returned => true).join(' ')
|
21
18
|
>> output.include? 'a = 33'
|
22
19
|
=> true
|
@@ -41,7 +38,7 @@ it should return you something useful
|
|
41
38
|
=> false
|
42
39
|
|
43
40
|
it should work with Module
|
44
|
-
>> FFI::Library.ri_for(:attach_function
|
41
|
+
>> FFI::Library.ri_for(:attach_function, :want_the_description_returned => true).nil?
|
45
42
|
=> false
|
46
43
|
|
47
44
|
it should say c method for c
|
@@ -96,9 +93,11 @@ it should display the name
|
|
96
93
|
|
97
94
|
and arity
|
98
95
|
>> Pathname.instance_method(:children).desc(:want_the_description_returned => true).grep(/arity/)
|
99
|
-
=> ["sig: Pathname#children arity -1
|
96
|
+
=> ["sig: Pathname#children arity -1"]
|
100
97
|
|
101
|
-
|
98
|
+
it should not duplicate arity
|
99
|
+
>> A.ri_for(:go, :want_the_description_returned => true).join(' ').scan(/arity/).length
|
100
|
+
=> 1
|
102
101
|
|
103
102
|
wurx with class methods
|
104
103
|
>> class A; def self.go(a = 3); a=5; end; end
|