inch 0.4.2 → 0.4.3.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b2d25865d4af4a7a7d2d8ae09344ac7b828148e
4
- data.tar.gz: dc387ecfacf69092c3344fc5c1b4bfe7229087b0
3
+ metadata.gz: 8df11f0c3f8e4f6ac9aea9b24fc63cd6ecc9d31f
4
+ data.tar.gz: b91f994c074b34d6d67f81ee36b17c6029c8961d
5
5
  SHA512:
6
- metadata.gz: 248469d48cdaf7dd7ffc82614a3e043ecde92ce800f5d64c271f8f268d0f5b20a7e7ee3f34a05a2a611cae3e5be128af02adc013490546343abe7dd5a4412c74
7
- data.tar.gz: af2f65be144c7edc0367f8bde04e1bc97cacbe0afcf0947c1fbe62cb8bb14b2236b412e884b3442df133729884168a4be0a7881a65f03376db97d5791d86a6e7
6
+ metadata.gz: e98e2c4bbcf6f32fd6fb9df7b03be207be2d92d103615493b9be1859d1f4fe14e90292d89c4d3cf4090f11d7f2e38c5d8b9cf4b7299cdb5ae6963e02320fbd14
7
+ data.tar.gz: 8cd1a2706a738a6cb5d4fe970d09aa519e058494c66cdf3d84e4def4b054d600ad49af9634a0f1965b9c42c452f3765b103a97f7b04effa3d7b78943b7f5f5ea
@@ -3,3 +3,13 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - 2.1.0
6
+ - ruby-head
7
+ - jruby-head
8
+ - jruby-19mode
9
+ - rbx-2.2.3
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: ruby-head
13
+ - rvm: jruby-head
14
+ - rvm: jruby-19mode
15
+ - rvm: rbx-2.2.3
@@ -7,13 +7,14 @@ module Inch
7
7
  class << self
8
8
  # Returns the columns of the terminal window
9
9
  # (defaults to 80)
10
+ # @param default [Fixnum] default value for columns
10
11
  # @return [Fixnum]
11
- def get_term_columns
12
+ def get_term_columns(default = 80)
12
13
  str = `stty size`
13
14
  rows_cols = str.split(' ').map(&:to_i)
14
- rows_cols[1]
15
+ rows_cols[1] || default
15
16
  rescue
16
- 80
17
+ default
17
18
  end
18
19
  end
19
20
  COLUMNS = get_term_columns
@@ -28,12 +28,14 @@ module Inch
28
28
  end
29
29
 
30
30
  def describes_parameter?(name)
31
+ return false if name.nil?
31
32
  describe_parameter_regexps(name).any? do |pattern|
32
33
  @text.index(pattern)
33
34
  end
34
35
  end
35
36
 
36
37
  def mentions_parameter?(name)
38
+ return false if name.nil?
37
39
  mention_parameter_regexps(name).any? do |pattern|
38
40
  @text.index(pattern)
39
41
  end
@@ -20,7 +20,7 @@ module Inch
20
20
  CONSIDERED_YARD_TAGS = %w(api example param private return since)
21
21
 
22
22
  # convenient shortcuts to (YARD) code object
23
- def_delegators :object, :type, :namespace, :source, :source_type, :signature, :group, :dynamic, :visibility
23
+ def_delegators :object, :type, :namespace, :source, :source_type, :group, :dynamic, :visibility
24
24
 
25
25
  # @param object [YARD::CodeObjects::Base] the actual (YARD) code object
26
26
  def initialize(object)
@@ -227,7 +227,7 @@ module Inch
227
227
  end
228
228
 
229
229
  def inspect
230
- "#<#{self.class.to_s}: #{path}>"
230
+ "#<#{self.class.to_s}: #{fullname}>"
231
231
  end
232
232
 
233
233
  protected
@@ -1,3 +1,5 @@
1
+ require_relative 'method_signature'
2
+
1
3
  module Inch
2
4
  module CodeObject
3
5
  module Provider
@@ -28,7 +30,7 @@ module Inch
28
30
  end
29
31
 
30
32
  def has_doc?
31
- super && !implicit_docstring? || overload_tags.any? { |t| !t.docstring.empty? }
33
+ super && !implicit_docstring? || signatures.any? { |t| t.has_doc? }
32
34
  end
33
35
 
34
36
  def method?
@@ -36,13 +38,7 @@ module Inch
36
38
  end
37
39
 
38
40
  def parameters
39
- @parameters ||= all_parameter_names.map do |name|
40
- signature_name = in_signature(name)
41
- tag = parameter_tag(name) || parameter_tag(signature_name) ||
42
- param_tag_in_overload_tags(name) ||
43
- param_tag_in_overload_tags(signature_name)
44
- MethodParameterObject.new(self, name, signature_name, tag)
45
- end
41
+ @parameters ||= signatures.map(&:parameters).flatten
46
42
  end
47
43
 
48
44
  def parameter(name)
@@ -80,18 +76,19 @@ module Inch
80
76
  name =~ /\=$/ && parameters.size == 1
81
77
  end
82
78
 
79
+ def signatures
80
+ [self, *overload_tags].map do |tag_or_self|
81
+ MethodSignature.new(self, tag_or_self)
82
+ end
83
+ end
84
+
83
85
  def questioning_name?
84
86
  name =~ /\?$/
85
87
  end
86
88
 
87
89
  private
88
90
 
89
- def all_parameter_names
90
- names = signature_parameter_names
91
- names.concat parameter_tags.map(&:name)
92
- names.compact.map { |name| name.gsub(/[\*\&]/, '') }.uniq
93
- end
94
-
91
+ # Returns +true+ if the docstring was generated by YARD
95
92
  def implicit_docstring?
96
93
  if getter?
97
94
  docstring == "Returns the value of attribute #{name}"
@@ -103,58 +100,10 @@ module Inch
103
100
  end
104
101
  end
105
102
 
106
- def in_signature(name)
107
- possible_names = [name, "*#{name}", "&#{name}"]
108
- (signature_parameter_names & possible_names).first
109
- end
110
-
111
- def normalize_parameter_name(name)
112
- # remove leading and trailing brackets
113
- # (sometimes used to indicate optional parameters in overload
114
- # signatures)
115
- name.gsub(/[\[\]]/, '')
116
- end
117
-
118
103
  def overload_tags
119
104
  object.tags(:overload)
120
105
  end
121
106
 
122
- # Returns all parameter names from all overload signatures.
123
- # @todo analyse each signature on its own
124
- def overloaded_parameter_names
125
- overload_tags.map do |tag|
126
- Array(tag.parameters).map do |parameter|
127
- normalize_parameter_name(parameter[0])
128
- end
129
- end.flatten
130
- end
131
-
132
- def param_tag_in_overload_tags(name)
133
- overload_tags.map do |overload_tag|
134
- find_param_tag(overload_tag, name)
135
- end.first
136
- end
137
-
138
- def find_param_tag(overload_tag, name)
139
- overload_tag.tags(:param).detect do |param_tag|
140
- param_tag.name == name
141
- end
142
- end
143
-
144
- def signature_parameter_names
145
- object.parameters.map(&:first) + overloaded_parameter_names
146
- end
147
-
148
- def parameter_tag(param_name)
149
- parameter_tags.detect do |tag|
150
- tag.name == param_name
151
- end
152
- end
153
-
154
- def parameter_tags
155
- object.tags(:param)
156
- end
157
-
158
107
  def return_tags
159
108
  object.tags(:return) + overloaded_return_tags
160
109
  end
@@ -0,0 +1,109 @@
1
+ module Inch
2
+ module CodeObject
3
+ module Provider
4
+ module YARD
5
+ module Object
6
+ # Utility class to describe (overloaded) method signatures
7
+ class MethodSignature < Struct.new(:method, :tag_or_method)
8
+ def has_code_example?
9
+ !yard_object.tags(:example).empty?
10
+ end
11
+
12
+ def has_doc?
13
+ !docstring.empty?
14
+ end
15
+
16
+ def parameters
17
+ @parameters ||= all_parameter_names.map do |name|
18
+ signature_name = in_signature(name)
19
+ tag = parameter_tag(name) || parameter_tag(signature_name)
20
+ MethodParameterObject.new(method, name, signature_name, tag)
21
+ end
22
+ end
23
+
24
+ def parameter(name)
25
+ parameters.detect { |p| p.name == name.to_s }
26
+ end
27
+
28
+ # Returns the actual signature of the method.
29
+ # @return [String]
30
+ def signature
31
+ if tag?
32
+ tag_or_method.signature
33
+ else
34
+ yard_object.signature.gsub(/^(def\ )/, '')
35
+ end
36
+ end
37
+
38
+ #private
39
+
40
+ def all_parameter_names
41
+ all_names = all_signature_parameter_names + parameter_tags.map(&:name)
42
+ all_names.map do |name|
43
+ normalize_parameter_name(name) if name
44
+ end.compact.uniq
45
+ end
46
+
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
+ def docstring
56
+ if tag?
57
+ tag_or_method.docstring
58
+ else
59
+ yard_object.docstring
60
+ end
61
+ end
62
+
63
+ # Returns how the given parameter is noted in the method's
64
+ # signature.
65
+ #
66
+ # @param name [String] parameter name
67
+ # @return [String]
68
+ def in_signature(name)
69
+ possible_names = [name, "*#{name}", "&#{name}"]
70
+ (all_signature_parameter_names & possible_names).first
71
+ end
72
+
73
+ # Removes block, splat symbols, dollar sign,
74
+ # leading and trailing brackets from a given +name+
75
+ # (sometimes used to indicate optional parameters in overload
76
+ # signatures).
77
+ # @param name [String] parameter name
78
+ # @return [String]
79
+ def normalize_parameter_name(name)
80
+ name.gsub(/[\&\*\$\[\]]/, '')
81
+ end
82
+
83
+ def parameter_tag(param_name)
84
+ parameter_tags.detect do |tag|
85
+ tag.name == param_name
86
+ end
87
+ end
88
+
89
+ def parameter_tags
90
+ if tag?
91
+ tag_or_method.tags(:param)
92
+ else
93
+ yard_object.tags(:param)
94
+ end
95
+ end
96
+
97
+ def tag?
98
+ tag_or_method.respond_to?(:signature)
99
+ end
100
+
101
+ def yard_object
102
+ tag_or_method.object
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -9,7 +9,7 @@ module Inch
9
9
  # Helper method to parse an instance with the given +args+
10
10
  #
11
11
  # @see #parse
12
- # @return [CodeObject::Provider::YARD] the instance that ran
12
+ # @return [CodeObject::Provider::YARD::Parser] the instance that ran
13
13
  def self.parse(*args)
14
14
  parser = self.new
15
15
  parser.parse(*args)
@@ -1,3 +1,3 @@
1
1
  module Inch
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3.rc1"
3
3
  end
@@ -179,6 +179,28 @@ module Overloading
179
179
  # @return [void]
180
180
  def missing_param_names(*identifiers)
181
181
  end
182
+
183
+ # Creates a Hello OpenFlow message.
184
+ #
185
+ # @overload params_only_in_overloads()
186
+ # @example
187
+ # Hello.new
188
+ #
189
+ # @overload params_only_in_overloads(transaction_id)
190
+ # @example
191
+ # Hello.new(123)
192
+ # @param [Number] transaction_id
193
+ # An unsigned 32-bit integer number associated with this
194
+ # message. If not specified, an auto-generated value is set.
195
+ #
196
+ # @example
197
+ # Hello.new(transaction_id: 123)
198
+ # Hello.new(xid: 123)
199
+ # @param [Hash] user_options the options to create a message with.
200
+ # @option user_options [Number] :transaction_id
201
+ # @option user_options [Number] :xid an alias to transaction_id.
202
+ def params_only_in_overloads(user_options = {})
203
+ end
182
204
  end
183
205
 
184
206
  module YardError
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../../../test_helper')
2
+
3
+ describe ::Inch::CodeObject::Provider::YARD::Parser do
4
+ before do
5
+ @config = Inch::Config.codebase
6
+ @parser = ::Inch::CodeObject::Provider::YARD::Parser.parse(fixture_path(:simple), @config)
7
+ @objects = @parser.objects
8
+ end
9
+
10
+ it "should work for Overloading#params_only_in_overloads" do
11
+ m = @objects.detect { |o| o.fullname == 'Overloading#params_only_in_overloads' }
12
+
13
+ assert m.has_code_example?
14
+
15
+ refute m.signatures.empty?
16
+ assert_equal 3, m.signatures.size
17
+ assert_equal 2, m.parameters.size # at this moment, this counts all parameters in all overloaded signatures
18
+
19
+ signature = m.signatures[0]
20
+ assert_equal "params_only_in_overloads(user_options = {})", signature.signature
21
+ assert_equal 1, signature.parameters.size
22
+ refute signature.parameter(:user_options).nil?
23
+ assert signature.has_code_example?
24
+ assert signature.has_doc?
25
+
26
+ signature = m.signatures[1]
27
+ assert_equal "params_only_in_overloads()", signature.signature
28
+ assert signature.parameters.empty?, "Should have been empty: #{signature.parameters.inspect}"
29
+ assert signature.has_code_example?
30
+ refute signature.has_doc?
31
+
32
+ signature = m.signatures[2]
33
+ assert_equal "params_only_in_overloads(transaction_id)", signature.signature
34
+ assert_equal 1, signature.parameters.size
35
+ refute signature.parameter(:transaction_id).nil?
36
+ assert signature.has_code_example?
37
+ refute signature.has_doc?
38
+ end
39
+
40
+ it "should work" do
41
+ m = @objects.detect { |o| o.fullname == 'Foo::Bar#method_with_unstructured_doc' }
42
+ assert_equal 1, m.signatures.size
43
+ assert_equal 1, m.parameters.size
44
+ end
45
+
46
+ it "should work 2" do
47
+ m = @objects.detect { |o| o.fullname == 'Foo#method_with_splat_parameter' }
48
+ assert_equal 1, m.signatures.size
49
+ assert_equal 1, m.parameters.size
50
+ end
51
+
52
+ end
@@ -259,8 +259,12 @@ describe ::Inch::CodeObject::Proxy::MethodObject do
259
259
  end
260
260
 
261
261
  def test_splat_parameter_notation
262
+ # it should assign the same score whether the parameter is
263
+ # described with or without the splat (*) operator
262
264
  m1 = @objects.find("Foo#method_with_splat_parameter")
263
265
  m2 = @objects.find("Foo#method_with_splat_parameter2")
266
+ assert_equal 1, m1.parameters.size
267
+ assert_equal 1, m2.parameters.size
264
268
  assert_equal m1.score, m2.score
265
269
  end
266
270
 
@@ -278,6 +282,7 @@ describe ::Inch::CodeObject::Proxy::MethodObject do
278
282
  list << @objects.find("Overloading#mix")
279
283
  list << @objects.find("Overloading#hooks")
280
284
  list << @objects.find("Overloading#identifiers")
285
+ list << @objects.find("Overloading#params_only_in_overloads")
281
286
  list.each do |m|
282
287
  assert_equal 100, m.score, "#{m.fullname} did not get 100"
283
288
  end
@@ -287,4 +292,17 @@ describe ::Inch::CodeObject::Proxy::MethodObject do
287
292
  m = @objects.find("Overloading#missing_param_names")
288
293
  refute m.has_doc? # it may be mentioned in the docs, but it's malformed.
289
294
  end
295
+
296
+ def test_overloading_with_bad_doc
297
+ m = @objects.find("Overloading#params_only_in_overloads")
298
+ roles = m.roles.map(&:class)
299
+ bad_roles = [
300
+ Inch::Evaluation::Role::Object::WithoutCodeExample,
301
+ Inch::Evaluation::Role::MethodParameter::WithoutMention,
302
+ Inch::Evaluation::Role::MethodParameter::WithoutType,
303
+ ]
304
+ bad_roles.each do |role|
305
+ refute roles.include?(role), "Should not assign #{role}"
306
+ end
307
+ end
290
308
  end
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.2
4
+ version: 0.4.3.rc1
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-10 00:00:00.000000000 Z
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -192,6 +192,7 @@ files:
192
192
  - lib/inch/code_object/provider/yard/object/constant_object.rb
193
193
  - lib/inch/code_object/provider/yard/object/method_object.rb
194
194
  - lib/inch/code_object/provider/yard/object/method_parameter_object.rb
195
+ - lib/inch/code_object/provider/yard/object/method_signature.rb
195
196
  - lib/inch/code_object/provider/yard/object/module_object.rb
196
197
  - lib/inch/code_object/provider/yard/object/namespace_object.rb
197
198
  - lib/inch/code_object/provider/yard/object/root_object.rb
@@ -288,6 +289,7 @@ files:
288
289
  - test/unit/code_object/converter_test.rb
289
290
  - test/unit/code_object/provider/yard/docstring_test.rb
290
291
  - test/unit/code_object/provider/yard/nodoc_helper_test.rb
292
+ - test/unit/code_object/provider/yard/object/method_object_test.rb
291
293
  - test/unit/code_object/provider/yard_test.rb
292
294
  - test/unit/code_object/provider_test.rb
293
295
  - test/unit/code_object/proxy/method_object_test.rb
@@ -313,9 +315,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
313
315
  version: '0'
314
316
  required_rubygems_version: !ruby/object:Gem::Requirement
315
317
  requirements:
316
- - - ">="
318
+ - - ">"
317
319
  - !ruby/object:Gem::Version
318
- version: '0'
320
+ version: 1.3.1
319
321
  requirements: []
320
322
  rubyforge_project:
321
323
  rubygems_version: 2.2.2
@@ -370,6 +372,7 @@ test_files:
370
372
  - test/unit/code_object/converter_test.rb
371
373
  - test/unit/code_object/provider/yard/docstring_test.rb
372
374
  - test/unit/code_object/provider/yard/nodoc_helper_test.rb
375
+ - test/unit/code_object/provider/yard/object/method_object_test.rb
373
376
  - test/unit/code_object/provider/yard_test.rb
374
377
  - test/unit/code_object/provider_test.rb
375
378
  - test/unit/code_object/proxy/method_object_test.rb