yard-heuristics 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ef6b420a250a2fdfea079c60c2fcc989606c887
4
+ data.tar.gz: 10858faf20695c998243c94e2b92f4d4e2d4e7b8
5
+ SHA512:
6
+ metadata.gz: bb2f1c75cafee7dee1e602ed5f7f5aa113e2510c9560cbb408ccc273a73a56efb38a9fb5de3cedc87b23634b74ef2a2c3b77da3380469ad26bcd493b92d93dfd
7
+ data.tar.gz: a64b570b41ab01e735dbf4838ca6fae4752db49c416336f0a9ec1cb698945c6f2ea5e3199d151eaef0dfd23dc31ead7db82ee59d164be9b35579623639204cca
data/README CHANGED
@@ -1,4 +1,177 @@
1
1
  YARD-Heuristics
2
2
 
3
3
  YARD-Heuristics heuristically determines types of parameters and return
4
- values to YARD.
4
+ values for YARD documentation that doesn’t explicitly document it. This
5
+ allows you to write documentation that isn’t adorned with “obvious” types,
6
+ but still get that information into the output. It also lets you
7
+ nice-looking references to parameters and have them be marked up
8
+ appropriately in HTML output.
9
+
10
+ § Heuristics
11
+
12
+ The following sections list the various heuristics that YARD-Heuristics
13
+ apply for determining types of parameters and return values.
14
+
15
+ Note that for all heuristics, a type will only be added if none already
16
+ exists.
17
+
18
+ § Parameter Named “other”
19
+
20
+ A parameter named “other” has the same type as the receiver. This turns
21
+
22
+ class Point
23
+ def ==(other)
24
+
25
+ into
26
+
27
+ class Point
28
+ # @param [Point] other
29
+ def ==(other)
30
+
31
+ § Parameter Types Derived by Parameter Name
32
+
33
+ Parameters to a method with names in the following table has the type
34
+ listed on the same row.
35
+
36
+ | Name | Type |
37
+ |--------+-----------|
38
+ | index | [Integer] |
39
+ | object | [Object] |
40
+ | range | [Range] |
41
+ | string | [String] |
42
+
43
+ Thus
44
+
45
+ class Point
46
+ def x_inside?(range)
47
+
48
+ becomes
49
+
50
+ class Point
51
+ # @param [Range] range
52
+ def x_inside?(range)
53
+
54
+ § Block Parameters
55
+
56
+ If the last parameter to a method’s name begins with ‘&’ it has the type
57
+ [Proc].
58
+
59
+ class Method
60
+ def initialize(&block)
61
+
62
+ becomes
63
+
64
+ class Method
65
+ # @param [Block] block
66
+ def initialize(&block)
67
+
68
+ § Return Types by Method Name
69
+
70
+ For the return type of a method with less than two ‹@return› tags, the
71
+ method name is lookup up in the following table and has the type listed on
72
+ the same row. For the “type” “self or type”, if a ‹@param› tag exists with
73
+ the name “other”, the type of the receiver is used, otherwise “self” is
74
+ used. For the “type” “type”, the type of the receiver is used.
75
+
76
+ | Name | Type |
77
+ |-----------------+----------------|
78
+ | ‹<<› | self or type |
79
+ | ‹>>› | self or type |
80
+ | ‹==› | [Boolean] |
81
+ | ‹===› | [Boolean] |
82
+ | ‹=~› | [Boolean] |
83
+ | ‹<=>› | [Integer, nil] |
84
+ | ‹+› | type |
85
+ | ‹-› | type |
86
+ | ‹*› | type |
87
+ | ‹/› | type |
88
+ | each | [self] |
89
+ | each_with_index | [self] |
90
+ | hash | [Integer] |
91
+ | inspect | [String] |
92
+ | length | [Integer] |
93
+ | size | [Integer] |
94
+ | to_s | [String] |
95
+ | to_str | [String] |
96
+
97
+
98
+ Thus
99
+
100
+ class Point
101
+ def <<(other)
102
+
103
+ becomes
104
+
105
+ class Point
106
+ # @return [Point]
107
+ def <<(other)
108
+
109
+ but
110
+
111
+ class List
112
+ def <<(item)
113
+
114
+ becomes
115
+
116
+ class List
117
+ # @return [self]
118
+ def <<(item)
119
+
120
+ § Emphasizing Parameter Names
121
+
122
+ When producing HTML output, any words in all uppercase, with a possible
123
+ “th” suffix, that is also the name of a parameter, an ‹@option›, or a
124
+ ‹@yieldparam›, will be downcased and emphasized with a class of
125
+ “parameter”.
126
+
127
+ In the following example, “OTHER” will be turned into
128
+ ‹<em class="parameter">other</em>›:
129
+
130
+ class Point
131
+ # @return True if the receiver’s class and {#x} and {#y} `#==` those of
132
+ # OTHER
133
+ def ==(other)
134
+
135
+ § Usage
136
+
137
+ Add ‹--plugin yard-heuristics-1.0› to your YARD command line. If you’re
138
+ using Inventory-Rake-Tasks-YARD¹, add the following to your Rakefile:
139
+
140
+ Inventory::Rake::Tasks::YARD.new do |t|
141
+ t.options += %w'--plugin yard-heuristics-1.0'
142
+ end
143
+
144
+ ¹ See http://disu.se/software/inventory-rake-tasks-yard/
145
+
146
+ § API
147
+
148
+ There’s really not very much to the YARD-Heuristics API. What you can do
149
+ is add (or modify) the types of parameters and return types of methods by
150
+ adding (or modifying) entries in the Hash tables
151
+ ‹YARDHeuristics::ParamTypes› and ‹YARDHeuristics::ReturnTypes›
152
+ respectively. That’s about it.
153
+
154
+ § Financing
155
+
156
+ Currently, most of my time is spent at my day job and in my rather busy
157
+ private life. Please motivate me to spend time on this piece of software
158
+ by donating some of your money to this project. Yeah, I realize that
159
+ requesting money to develop software is a bit, well, capitalistic of me.
160
+ But please realize that I live in a capitalistic society and I need money
161
+ to have other people give me the things that I need to continue living
162
+ under the rules of said society. So, if you feel that this piece of
163
+ software has helped you out enough to warrant a reward, please PayPal a
164
+ donation to now@disu.se¹. Thanks! Your support won’t go unnoticed!
165
+
166
+ ¹ Send a donation:
167
+ https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now%40disu%2ese&item_name=Nikolai%20Weibull%20Software%20Services
168
+
169
+ § Reporting Bugs
170
+
171
+ Please report any bugs that you encounter to the {issue tracker}¹.
172
+
173
+ ¹ See https://github.com/now/yard-heuristics/issues
174
+
175
+ § Authors
176
+
177
+ Nikolai Weibull wrote the code, the tests, and this README.
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require 'inventory/rake-1.0'
3
+ require 'inventory-rake-1.0'
4
4
 
5
- load File.expand_path('../lib/yard-heuristics/version.rb', __FILE__)
5
+ load File.expand_path('../lib/yard-heuristics-1.0/version.rb', __FILE__)
6
6
 
7
7
  Inventory::Rake::Tasks.define YARDHeuristics::Version, :gem => proc{ |_, s|
8
8
  s.author = 'Nikolai Weibull'
@@ -11,7 +11,7 @@ Inventory::Rake::Tasks.define YARDHeuristics::Version, :gem => proc{ |_, s|
11
11
  }
12
12
 
13
13
  Inventory::Rake::Tasks.unless_installing_dependencies do
14
- require 'lookout/rake-3.0'
14
+ require 'lookout-rake-3.0'
15
15
  # TODO: Silence warnings generated from YARD (remove this once we plug them)
16
16
  Lookout::Rake::Tasks::Test.new :options => []
17
17
  end
@@ -1,8 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- # Namespace for YARD heuristics.
3
+ # Namespace for YARD-Heuristics.
4
4
  module YARDHeuristics
5
- load File.expand_path('../yard-heuristics/version.rb', __FILE__)
5
+ load File.expand_path('../yard-heuristics-1.0/version.rb', __FILE__)
6
6
  Version.load
7
7
 
8
8
  ParamTypes = {
@@ -111,8 +111,11 @@ module YARD::Templates::Helpers::HtmlHelper
111
111
  else
112
112
  parameter = $1.downcase
113
113
  ((object.parameters.assoc(parameter) ||
114
+ object.parameters.assoc(parameter + ':') ||
114
115
  object.parameters.assoc('*' + parameter) ||
116
+ object.parameters.assoc('**' + parameter) ||
115
117
  object.parameters.assoc('&' + parameter) ||
118
+ object.tags.find{ |e| e.tag_name == 'option' and e.pair.name == ':' + parameter } ||
116
119
  object.tags.find{ |e| e.tag_name == 'yieldparam' and e.name == parameter }) ?
117
120
  '<em class="parameter">%s</em>' % parameter :
118
121
  $1) + $2.to_s
@@ -3,10 +3,10 @@
3
3
  require 'inventory-1.0'
4
4
 
5
5
  module YARDHeuristics
6
- Version = Inventory.new(1, 1, 0){
6
+ Version = Inventory.new(1, 2, 0){
7
7
  def dependencies
8
8
  super + Inventory::Dependencies.new{
9
- development 'inventory-rake', 1, 3, 0
9
+ development 'inventory-rake', 1, 4, 0
10
10
  development 'lookout', 3, 0, 0
11
11
  development 'lookout-rake', 3, 0, 0
12
12
  runtime 'yard', 0, 8, 0, :feature => 'yard'
@@ -200,6 +200,31 @@ EOS
200
200
  # @yieldparam [Exception] exception
201
201
  def a
202
202
  end
203
+ EOS
204
+ Module.new{
205
+ class << self
206
+ include YARD::Templates::Helpers::HtmlHelper
207
+ def options
208
+ YARD::Templates::TemplateOptions.new{ |o|
209
+ o.reset_defaults
210
+ }
211
+ end
212
+ def object
213
+ YARD::Registry.at('#a')
214
+ end
215
+ end
216
+ }.instance_eval{
217
+ htmlify(YARD::Registry.at('#a').docstring)
218
+ }
219
+ end
220
+
221
+ expect 'Yields the <em class="parameter">exception</em>.' do
222
+ YARD::Registry.clear
223
+ YARD::Parser::SourceParser.parse_string(<<EOS)
224
+ # Yields the EXCEPTION.
225
+ # @option options [Exception] :exception
226
+ def a(options = {})
227
+ end
203
228
  EOS
204
229
  Module.new{
205
230
  class << self
metadata CHANGED
@@ -1,82 +1,272 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-heuristics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nikolai Weibull
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-08-03 00:00:00.000000000 Z
11
+ date: 2013-04-30 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: inventory
16
- requirement: &15442740 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: '1.3'
19
+ version: '1.4'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *15442740
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: inventory-rake
27
- requirement: &15441408 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ~>
31
32
  - !ruby/object:Gem::Version
32
- version: '1.3'
33
+ version: '1.4'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *15441408
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: lookout
38
- requirement: &15440268 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
45
  - - ~>
42
46
  - !ruby/object:Gem::Version
43
47
  version: '3.0'
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *15440268
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: lookout-rake
49
- requirement: &15438504 !ruby/object:Gem::Requirement
50
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
54
61
  version: '3.0'
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *15438504
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: yard
60
- requirement: &15436296 !ruby/object:Gem::Requirement
61
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
62
72
  requirements:
63
73
  - - ~>
64
74
  - !ruby/object:Gem::Version
65
75
  version: 0.8.0
66
76
  type: :runtime
67
77
  prerelease: false
68
- version_requirements: *15436296
69
- description: ! " YARD-Heuristics\n\n YARD-Heuristics
70
- heuristically determines types of parameters and return\n values to YARD.\n"
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.0
83
+ description: |2
84
+ YARD-Heuristics
85
+
86
+ YARD-Heuristics heuristically determines types of parameters and return
87
+ values for YARD documentation that doesn’t explicitly document it. This
88
+ allows you to write documentation that isn’t adorned with “obvious” types,
89
+ but still get that information into the output. It also lets you
90
+ nice-looking references to parameters and have them be marked up
91
+ appropriately in HTML output.
92
+
93
+ § Heuristics
94
+
95
+ The following sections list the various heuristics that YARD-Heuristics
96
+ apply for determining types of parameters and return values.
97
+
98
+ Note that for all heuristics, a type will only be added if none already
99
+ exists.
100
+
101
+ § Parameter Named “other”
102
+
103
+ A parameter named “other” has the same type as the receiver. This turns
104
+
105
+ class Point
106
+ def ==(other)
107
+
108
+ into
109
+
110
+ class Point
111
+ # @param [Point] other
112
+ def ==(other)
113
+
114
+ § Parameter Types Derived by Parameter Name
115
+
116
+ Parameters to a method with names in the following table has the type
117
+ listed on the same row.
118
+
119
+ | Name | Type |
120
+ |--------+-----------|
121
+ | index | [Integer] |
122
+ | object | [Object] |
123
+ | range | [Range] |
124
+ | string | [String] |
125
+
126
+ Thus
127
+
128
+ class Point
129
+ def x_inside?(range)
130
+
131
+ becomes
132
+
133
+ class Point
134
+ # @param [Range] range
135
+ def x_inside?(range)
136
+
137
+ § Block Parameters
138
+
139
+ If the last parameter to a method’s name begins with ‘&’ it has the type
140
+ [Proc].
141
+
142
+ class Method
143
+ def initialize(&block)
144
+
145
+ becomes
146
+
147
+ class Method
148
+ # @param [Block] block
149
+ def initialize(&block)
150
+
151
+ § Return Types by Method Name
152
+
153
+ For the return type of a method with less than two ‹@return› tags, the
154
+ method name is lookup up in the following table and has the type listed on
155
+ the same row. For the “type” “self or type”, if a ‹@param› tag exists with
156
+ the name “other”, the type of the receiver is used, otherwise “self” is
157
+ used. For the “type” “type”, the type of the receiver is used.
158
+
159
+ | Name | Type |
160
+ |-----------------+----------------|
161
+ | ‹<<› | self or type |
162
+ | ‹>>› | self or type |
163
+ | ‹==› | [Boolean] |
164
+ | ‹===› | [Boolean] |
165
+ | ‹=~› | [Boolean] |
166
+ | ‹<=>› | [Integer, nil] |
167
+ | ‹+› | type |
168
+ | ‹-› | type |
169
+ | ‹*› | type |
170
+ | ‹/› | type |
171
+ | each | [self] |
172
+ | each_with_index | [self] |
173
+ | hash | [Integer] |
174
+ | inspect | [String] |
175
+ | length | [Integer] |
176
+ | size | [Integer] |
177
+ | to_s | [String] |
178
+ | to_str | [String] |
179
+
180
+
181
+ Thus
182
+
183
+ class Point
184
+ def <<(other)
185
+
186
+ becomes
187
+
188
+ class Point
189
+ # @return [Point]
190
+ def <<(other)
191
+
192
+ but
193
+
194
+ class List
195
+ def <<(item)
196
+
197
+ becomes
198
+
199
+ class List
200
+ # @return [self]
201
+ def <<(item)
202
+
203
+ § Emphasizing Parameter Names
204
+
205
+ When producing HTML output, any words in all uppercase, with a possible
206
+ “th” suffix, that is also the name of a parameter, an ‹@option›, or a
207
+ ‹@yieldparam›, will be downcased and emphasized with a class of
208
+ “parameter”.
209
+
210
+ In the following example, “OTHER” will be turned into
211
+ ‹<em class="parameter">other</em>›:
212
+
213
+ class Point
214
+ # @return True if the receiver’s class and {#x} and {#y} `#==` those of
215
+ # OTHER
216
+ def ==(other)
217
+
218
+ § Usage
219
+
220
+ Add ‹--plugin yard-heuristics-1.0› to your YARD command line. If you’re
221
+ using Inventory-Rake-Tasks-YARD¹, add the following to your Rakefile:
222
+
223
+ Inventory::Rake::Tasks::YARD.new do |t|
224
+ t.options += %w'--plugin yard-heuristics-1.0'
225
+ end
226
+
227
+ ¹ See http://disu.se/software/inventory-rake-tasks-yard/
228
+
229
+ § API
230
+
231
+ There’s really not very much to the YARD-Heuristics API. What you can do
232
+ is add (or modify) the types of parameters and return types of methods by
233
+ adding (or modifying) entries in the Hash tables
234
+ ‹YARDHeuristics::ParamTypes› and ‹YARDHeuristics::ReturnTypes›
235
+ respectively. That’s about it.
236
+
237
+ § Financing
238
+
239
+ Currently, most of my time is spent at my day job and in my rather busy
240
+ private life. Please motivate me to spend time on this piece of software
241
+ by donating some of your money to this project. Yeah, I realize that
242
+ requesting money to develop software is a bit, well, capitalistic of me.
243
+ But please realize that I live in a capitalistic society and I need money
244
+ to have other people give me the things that I need to continue living
245
+ under the rules of said society. So, if you feel that this piece of
246
+ software has helped you out enough to warrant a reward, please PayPal a
247
+ donation to now@disu.se¹. Thanks! Your support won’t go unnoticed!
248
+
249
+ ¹ Send a donation:
250
+ https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now%40disu%2ese&item_name=Nikolai%20Weibull%20Software%20Services
251
+
252
+ § Reporting Bugs
253
+
254
+ Please report any bugs that you encounter to the {issue tracker}¹.
255
+
256
+ ¹ See https://github.com/now/yard-heuristics/issues
257
+
258
+ § Authors
259
+
260
+ Nikolai Weibull wrote the code, the tests, and this README.
71
261
  email: now@bitwi.se
72
262
  executables: []
73
263
  extensions: []
74
264
  extra_rdoc_files: []
75
265
  files:
76
266
  - lib/yard-heuristics-1.0.rb
77
- - lib/yard-heuristics/version.rb
267
+ - lib/yard-heuristics-1.0/version.rb
78
268
  - test/unit/yard-heuristics-1.0.rb
79
- - test/unit/yard-heuristics/version.rb
269
+ - test/unit/yard-heuristics-1.0/version.rb
80
270
  - README
81
271
  - Rakefile
82
272
  homepage: https://github.com/now/yard-heuristics
@@ -87,21 +277,19 @@ rdoc_options: []
87
277
  require_paths:
88
278
  - lib
89
279
  required_ruby_version: !ruby/object:Gem::Requirement
90
- none: false
91
280
  requirements:
92
- - - ! '>='
281
+ - - '>='
93
282
  - !ruby/object:Gem::Version
94
283
  version: '0'
95
284
  required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
285
  requirements:
98
- - - ! '>='
286
+ - - '>='
99
287
  - !ruby/object:Gem::Version
100
288
  version: '0'
101
289
  requirements: []
102
290
  rubyforge_project:
103
- rubygems_version: 1.8.10
291
+ rubygems_version: 2.0.0
104
292
  signing_key:
105
293
  specification_version: 4
106
- summary: values to YARD.
294
+ summary: values for YARD documentation that doesn’t explicitly document it.
107
295
  test_files: []