inch 0.4.3.rc1 → 0.4.3.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/inch/code_object/provider/yard/object/method_object.rb +13 -3
- data/lib/inch/code_object/provider/yard/object/method_signature.rb +36 -16
- data/lib/inch/version.rb +1 -1
- data/test/fixtures/simple/lib/broken.rb +26 -3
- data/test/unit/code_object/provider/yard/object/method_object_test.rb +33 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51a684b0122ca78cb12bfe784278c7f1e2aced3b
|
4
|
+
data.tar.gz: 047e6d479de69c949e4adf3c79f72ea63f5db753
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d6ef7ac83572913777a95e3408b54c1451d3d9c3a96772b30f106f0bf452b5fe28c0bf687b3e3caad58ec94342916b27bf62ddb6b3e86405bc738e1283d3782
|
7
|
+
data.tar.gz: c7fcf1abab329c2c18b84b11a1419b4aa5be23c852f4ea4403d82c1d09247d0fef3560fc3f799589d7e72bbdbcdae3c5300f8f8ad48d673403b4f26e97c0c2cc
|
@@ -29,8 +29,12 @@ module Inch
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def has_code_example?
|
33
|
+
super || signatures.any? { |s| s.has_code_example? }
|
34
|
+
end
|
35
|
+
|
32
36
|
def has_doc?
|
33
|
-
super && !implicit_docstring? || signatures.any? { |
|
37
|
+
super && !implicit_docstring? || signatures.any? { |s| s.has_doc? }
|
34
38
|
end
|
35
39
|
|
36
40
|
def method?
|
@@ -77,8 +81,14 @@ module Inch
|
|
77
81
|
end
|
78
82
|
|
79
83
|
def signatures
|
80
|
-
|
81
|
-
|
84
|
+
base = MethodSignature.new(self, nil)
|
85
|
+
overloaded = overload_tags.map do |tag|
|
86
|
+
MethodSignature.new(self, tag)
|
87
|
+
end
|
88
|
+
if overloaded.any? { |s| s.same?(base) }
|
89
|
+
overloaded
|
90
|
+
else
|
91
|
+
[base] + overloaded
|
82
92
|
end
|
83
93
|
end
|
84
94
|
|
@@ -4,9 +4,30 @@ module Inch
|
|
4
4
|
module YARD
|
5
5
|
module Object
|
6
6
|
# Utility class to describe (overloaded) method signatures
|
7
|
-
class MethodSignature < Struct.new(:method, :
|
7
|
+
class MethodSignature < Struct.new(:method, :yard_tag)
|
8
|
+
attr_reader :method, :yard_tag
|
9
|
+
|
10
|
+
# @param method [Provider::YARD::Object::MethodObject]
|
11
|
+
# @param method [::YARD::Tags::Tag,nil] if nil, the method's normal signature is used
|
12
|
+
def initialize(method, yard_tag = nil)
|
13
|
+
@method = method
|
14
|
+
@yard_tag = yard_tag
|
15
|
+
end
|
16
|
+
|
17
|
+
def all_signature_parameter_names
|
18
|
+
if tag?
|
19
|
+
yard_tag.parameters.map(&:first)
|
20
|
+
else
|
21
|
+
yard_object.parameters.map(&:first)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
8
25
|
def has_code_example?
|
9
|
-
|
26
|
+
if tag?
|
27
|
+
!yard_tag.tags(:example).empty?
|
28
|
+
else
|
29
|
+
!yard_object.tags(:example).empty?
|
30
|
+
end
|
10
31
|
end
|
11
32
|
|
12
33
|
def has_doc?
|
@@ -25,17 +46,24 @@ module Inch
|
|
25
46
|
parameters.detect { |p| p.name == name.to_s }
|
26
47
|
end
|
27
48
|
|
49
|
+
# Returns +true+ if the other signature is identical to self
|
50
|
+
# @param other [MethodSignature]
|
51
|
+
# @return [Boolean]
|
52
|
+
def same?(other)
|
53
|
+
all_signature_parameter_names == other.all_signature_parameter_names
|
54
|
+
end
|
55
|
+
|
28
56
|
# Returns the actual signature of the method.
|
29
57
|
# @return [String]
|
30
58
|
def signature
|
31
59
|
if tag?
|
32
|
-
|
60
|
+
yard_tag.signature
|
33
61
|
else
|
34
62
|
yard_object.signature.gsub(/^(def\ )/, '')
|
35
63
|
end
|
36
64
|
end
|
37
65
|
|
38
|
-
|
66
|
+
private
|
39
67
|
|
40
68
|
def all_parameter_names
|
41
69
|
all_names = all_signature_parameter_names + parameter_tags.map(&:name)
|
@@ -44,17 +72,9 @@ module Inch
|
|
44
72
|
end.compact.uniq
|
45
73
|
end
|
46
74
|
|
47
|
-
def all_signature_parameter_names
|
48
|
-
if tag?
|
49
|
-
tag_or_method.parameters.map(&:first)
|
50
|
-
else
|
51
|
-
yard_object.parameters.map(&:first)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
75
|
def docstring
|
56
76
|
if tag?
|
57
|
-
|
77
|
+
yard_tag.docstring
|
58
78
|
else
|
59
79
|
yard_object.docstring
|
60
80
|
end
|
@@ -88,18 +108,18 @@ module Inch
|
|
88
108
|
|
89
109
|
def parameter_tags
|
90
110
|
if tag?
|
91
|
-
|
111
|
+
@yard_tag.tags(:param)
|
92
112
|
else
|
93
113
|
yard_object.tags(:param)
|
94
114
|
end
|
95
115
|
end
|
96
116
|
|
97
117
|
def tag?
|
98
|
-
|
118
|
+
!yard_tag.nil?
|
99
119
|
end
|
100
120
|
|
101
121
|
def yard_object
|
102
|
-
|
122
|
+
method.object
|
103
123
|
end
|
104
124
|
end
|
105
125
|
end
|
data/lib/inch/version.rb
CHANGED
@@ -180,13 +180,13 @@ module Overloading
|
|
180
180
|
def missing_param_names(*identifiers)
|
181
181
|
end
|
182
182
|
|
183
|
-
#
|
183
|
+
# Tests that the default signature can be overloaded by tags
|
184
184
|
#
|
185
|
-
# @overload
|
185
|
+
# @overload params_also_in_overloads()
|
186
186
|
# @example
|
187
187
|
# Hello.new
|
188
188
|
#
|
189
|
-
# @overload
|
189
|
+
# @overload params_also_in_overloads(transaction_id)
|
190
190
|
# @example
|
191
191
|
# Hello.new(123)
|
192
192
|
# @param [Number] transaction_id
|
@@ -199,6 +199,29 @@ module Overloading
|
|
199
199
|
# @param [Hash] user_options the options to create a message with.
|
200
200
|
# @option user_options [Number] :transaction_id
|
201
201
|
# @option user_options [Number] :xid an alias to transaction_id.
|
202
|
+
def params_also_in_overloads(user_options = {})
|
203
|
+
end
|
204
|
+
|
205
|
+
# Tests that the default signature can be present as an overload tag.
|
206
|
+
#
|
207
|
+
# @overload params_only_in_overloads()
|
208
|
+
# @example
|
209
|
+
# Hello.new
|
210
|
+
#
|
211
|
+
# @overload params_only_in_overloads(transaction_id)
|
212
|
+
# @example
|
213
|
+
# Hello.new(123)
|
214
|
+
# @param [Number] transaction_id
|
215
|
+
# An unsigned 32-bit integer number associated with this
|
216
|
+
# message. If not specified, an auto-generated value is set.
|
217
|
+
#
|
218
|
+
# @overload params_only_in_overloads(user_options)
|
219
|
+
# @example
|
220
|
+
# Hello.new(transaction_id: 123)
|
221
|
+
# Hello.new(xid: 123)
|
222
|
+
# @param [Hash] user_options the options to create a message with.
|
223
|
+
# @option user_options [Number] :transaction_id
|
224
|
+
# @option user_options [Number] :xid an alias to transaction_id.
|
202
225
|
def params_only_in_overloads(user_options = {})
|
203
226
|
end
|
204
227
|
end
|
@@ -7,34 +7,62 @@ describe ::Inch::CodeObject::Provider::YARD::Parser do
|
|
7
7
|
@objects = @parser.objects
|
8
8
|
end
|
9
9
|
|
10
|
-
it "should work for Overloading#
|
11
|
-
m = @objects.detect { |o| o.fullname == 'Overloading#
|
10
|
+
it "should work for Overloading#params_also_in_overloads" do
|
11
|
+
m = @objects.detect { |o| o.fullname == 'Overloading#params_also_in_overloads' }
|
12
12
|
|
13
13
|
assert m.has_code_example?
|
14
14
|
|
15
|
-
refute m.signatures.empty?
|
16
15
|
assert_equal 3, m.signatures.size
|
17
16
|
assert_equal 2, m.parameters.size # at this moment, this counts all parameters in all overloaded signatures
|
18
17
|
|
19
18
|
signature = m.signatures[0]
|
20
|
-
assert_equal "
|
19
|
+
assert_equal "params_also_in_overloads(user_options = {})", signature.signature
|
21
20
|
assert_equal 1, signature.parameters.size
|
22
21
|
refute signature.parameter(:user_options).nil?
|
23
22
|
assert signature.has_code_example?
|
24
23
|
assert signature.has_doc?
|
25
24
|
|
26
25
|
signature = m.signatures[1]
|
27
|
-
assert_equal "
|
26
|
+
assert_equal "params_also_in_overloads()", signature.signature
|
28
27
|
assert signature.parameters.empty?, "Should have been empty: #{signature.parameters.inspect}"
|
29
28
|
assert signature.has_code_example?
|
30
29
|
refute signature.has_doc?
|
31
30
|
|
32
31
|
signature = m.signatures[2]
|
32
|
+
assert_equal "params_also_in_overloads(transaction_id)", signature.signature
|
33
|
+
assert_equal 1, signature.parameters.size
|
34
|
+
refute signature.parameter(:transaction_id).nil?
|
35
|
+
assert signature.has_code_example?
|
36
|
+
refute signature.has_doc?
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should work for Overloading#params_only_in_overloads" do
|
40
|
+
m = @objects.detect { |o| o.fullname == 'Overloading#params_only_in_overloads' }
|
41
|
+
|
42
|
+
assert m.has_code_example?
|
43
|
+
|
44
|
+
assert_equal 3, m.signatures.size
|
45
|
+
assert_equal 2, m.parameters.size # at this moment, this counts all parameters in all overloaded signatures
|
46
|
+
|
47
|
+
signature = m.signatures[0]
|
48
|
+
assert_equal "params_only_in_overloads()", signature.signature
|
49
|
+
assert signature.parameters.empty?, "Should have been empty: #{signature.parameters.inspect}"
|
50
|
+
assert signature.has_code_example?
|
51
|
+
refute signature.has_doc?
|
52
|
+
|
53
|
+
signature = m.signatures[1]
|
33
54
|
assert_equal "params_only_in_overloads(transaction_id)", signature.signature
|
34
55
|
assert_equal 1, signature.parameters.size
|
35
56
|
refute signature.parameter(:transaction_id).nil?
|
36
57
|
assert signature.has_code_example?
|
37
58
|
refute signature.has_doc?
|
59
|
+
|
60
|
+
signature = m.signatures[2]
|
61
|
+
assert_equal "params_only_in_overloads(user_options)", signature.signature
|
62
|
+
assert_equal 1, signature.parameters.size
|
63
|
+
refute signature.parameter(:user_options).nil?
|
64
|
+
assert signature.has_code_example?
|
65
|
+
#assert signature.has_doc?
|
38
66
|
end
|
39
67
|
|
40
68
|
it "should work" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.3.
|
4
|
+
version: 0.4.3.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- René Föhring
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|