yard 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yard might be problematic. Click here for more details.

Files changed (121) hide show
  1. data/ChangeLog +585 -1
  2. data/README.md +10 -2
  3. data/benchmarks/yri_cache.rb +19 -0
  4. data/bin/yri +1 -26
  5. data/docs/WhatsNew.md +99 -0
  6. data/lib/rubygems_plugin.rb +2 -0
  7. data/lib/yard.rb +2 -2
  8. data/lib/yard/autoload.rb +9 -4
  9. data/lib/yard/cli/base.rb +26 -0
  10. data/lib/yard/cli/yard_graph.rb +2 -9
  11. data/lib/yard/cli/yardoc.rb +93 -33
  12. data/lib/yard/cli/yri.rb +128 -0
  13. data/lib/yard/code_objects/base.rb +16 -5
  14. data/lib/yard/code_objects/class_object.rb +11 -4
  15. data/lib/yard/code_objects/method_object.rb +11 -1
  16. data/lib/yard/code_objects/proxy.rb +5 -2
  17. data/lib/yard/code_objects/root_object.rb +1 -0
  18. data/lib/yard/core_ext/file.rb +1 -1
  19. data/lib/yard/core_ext/hash.rb +15 -0
  20. data/lib/yard/core_ext/module.rb +2 -2
  21. data/lib/yard/core_ext/string.rb +66 -0
  22. data/lib/yard/core_ext/symbol_hash.rb +1 -1
  23. data/lib/yard/docstring.rb +5 -5
  24. data/lib/yard/handlers/base.rb +10 -4
  25. data/lib/yard/handlers/processor.rb +3 -4
  26. data/lib/yard/handlers/ruby/attribute_handler.rb +3 -2
  27. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -2
  28. data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -1
  29. data/lib/yard/handlers/ruby/method_handler.rb +7 -1
  30. data/lib/yard/logging.rb +11 -1
  31. data/lib/yard/parser/c_parser.rb +407 -0
  32. data/lib/yard/parser/ruby/ast_node.rb +2 -2
  33. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +3 -4
  34. data/lib/yard/parser/source_parser.rb +18 -7
  35. data/lib/yard/rake/yardoc_task.rb +1 -1
  36. data/lib/yard/registry.rb +83 -29
  37. data/lib/yard/registry_store.rb +213 -0
  38. data/lib/yard/serializers/base.rb +1 -1
  39. data/lib/yard/serializers/yardoc_serializer.rb +113 -0
  40. data/lib/yard/tags/library.rb +4 -0
  41. data/lib/yard/tags/overload_tag.rb +16 -5
  42. data/lib/yard/tags/tag.rb +1 -2
  43. data/lib/yard/templates/engine.rb +3 -3
  44. data/lib/yard/templates/helpers/html_helper.rb +50 -16
  45. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +1 -3
  46. data/lib/yard/templates/helpers/html_syntax_highlight_helper18.rb +1 -3
  47. data/lib/yard/templates/helpers/method_helper.rb +11 -4
  48. data/lib/yard/templates/helpers/text_helper.rb +24 -2
  49. data/lib/yard/verifier.rb +3 -3
  50. data/spec/cli/yardoc_spec.rb +33 -6
  51. data/spec/cli/yri_spec.rb +30 -0
  52. data/spec/code_objects/base_spec.rb +7 -0
  53. data/spec/code_objects/class_object_spec.rb +6 -1
  54. data/spec/code_objects/method_object_spec.rb +25 -0
  55. data/spec/core_ext/hash_spec.rb +10 -0
  56. data/spec/core_ext/module_spec.rb +1 -1
  57. data/spec/core_ext/string_spec.rb +50 -12
  58. data/spec/handlers/attribute_handler_spec.rb +4 -0
  59. data/spec/handlers/examples/method_handler_001.rb.txt +9 -0
  60. data/spec/handlers/method_handler_spec.rb +22 -4
  61. data/spec/parser/c_parser_spec.rb +22 -0
  62. data/spec/parser/examples/array.c.txt +3887 -0
  63. data/spec/parser/source_parser_spec.rb +29 -7
  64. data/spec/registry_spec.rb +93 -72
  65. data/spec/registry_store_spec.rb +184 -0
  66. data/spec/serializers/file_system_serializer_spec.rb +96 -75
  67. data/spec/spec_helper.rb +2 -2
  68. data/spec/tags/overload_tag_spec.rb +18 -0
  69. data/spec/templates/examples/class001.html +32 -30
  70. data/spec/templates/examples/method001.html +4 -1
  71. data/spec/templates/examples/method002.html +7 -2
  72. data/spec/templates/examples/method002.txt +1 -1
  73. data/spec/templates/examples/method003.html +30 -8
  74. data/spec/templates/examples/method003.txt +4 -4
  75. data/spec/templates/examples/method004.html +44 -0
  76. data/spec/templates/examples/method004.txt +10 -0
  77. data/spec/templates/examples/method005.html +99 -0
  78. data/spec/templates/examples/method005.txt +33 -0
  79. data/spec/templates/examples/module001.dot +1 -1
  80. data/spec/templates/examples/module001.html +391 -37
  81. data/spec/templates/examples/module001.txt +1 -1
  82. data/spec/templates/helpers/base_helper_spec.rb +2 -2
  83. data/spec/templates/helpers/html_helper_spec.rb +83 -0
  84. data/spec/templates/helpers/method_helper_spec.rb +47 -0
  85. data/spec/templates/helpers/shared_signature_examples.rb +102 -0
  86. data/spec/templates/helpers/text_helper_spec.rb +31 -0
  87. data/spec/templates/method_spec.rb +43 -18
  88. data/spec/templates/module_spec.rb +22 -1
  89. data/spec/templates/spec_helper.rb +10 -1
  90. data/spec/yard_spec.rb +4 -3
  91. data/templates/default/class/html/constructor_details.erb +1 -1
  92. data/templates/default/docstring/html/returns_void.erb +1 -0
  93. data/templates/default/docstring/setup.rb +9 -4
  94. data/templates/default/docstring/text/returns_void.erb +1 -0
  95. data/templates/default/fulldoc/html/css/style.css +4 -2
  96. data/templates/default/fulldoc/html/full_list.erb +2 -2
  97. data/templates/default/fulldoc/html/js/app.js +1 -1
  98. data/templates/default/fulldoc/html/setup.rb +14 -6
  99. data/templates/default/layout/dot/setup.rb +1 -1
  100. data/templates/default/layout/html/breadcrumb.erb +2 -2
  101. data/templates/default/layout/html/index.erb +2 -2
  102. data/templates/default/layout/html/setup.rb +5 -5
  103. data/templates/default/method/html/header.erb +6 -4
  104. data/templates/default/method_details/html/method_signature.erb +2 -1
  105. data/templates/default/method_details/html/source.erb +1 -1
  106. data/templates/default/method_details/setup.rb +2 -1
  107. data/templates/default/method_details/text/setup.rb +1 -1
  108. data/templates/default/module/html/attribute_details.erb +4 -4
  109. data/templates/default/module/html/attribute_summary.erb +3 -3
  110. data/templates/default/module/html/box_info.erb +2 -2
  111. data/templates/default/module/html/defines.erb +1 -1
  112. data/templates/default/module/html/inherited_constants.erb +1 -1
  113. data/templates/default/module/html/inherited_methods.erb +1 -1
  114. data/templates/default/module/html/item_summary.erb +13 -4
  115. data/templates/default/module/html/method_details_list.erb +5 -4
  116. data/templates/default/module/html/method_summary.erb +5 -4
  117. data/templates/default/module/html/methodmissing.erb +1 -1
  118. data/templates/default/module/setup.rb +14 -5
  119. data/templates/default/tags/html/overload.erb +3 -2
  120. data/templates/default/tags/setup.rb +4 -0
  121. metadata +23 -2
@@ -37,7 +37,7 @@ module YARD
37
37
  #
38
38
  # @abstract Should run code after serialization.
39
39
  # @param [String] data the data that was serialized.
40
- # @return [nil]
40
+ # @return [void]
41
41
  def after_serialize(data); end
42
42
 
43
43
  # Serializes an object.
@@ -0,0 +1,113 @@
1
+ module YARD
2
+ class StubProxy
3
+ instance_methods.each {|m| undef_method(m) unless m.to_s =~ /^__|^object_id$/ }
4
+
5
+ def _dump(depth) @path end
6
+ def self._load(str) new(str) end
7
+
8
+ def initialize(path, transient = false)
9
+ @path = path
10
+ @transient = transient
11
+ end
12
+
13
+ def method_missing(meth, *args, &block)
14
+ return true if meth == :respond_to? && args.first == :_dump
15
+ return Registry.at(@path).send(meth, *args, &block) if @transient
16
+ @object ||= Registry.at(@path)
17
+ @object.send(meth, *args, &block)
18
+ rescue NoMethodError => e
19
+ e.backtrace.delete_if {|l| l[0, __FILE__.size] == __FILE__ }
20
+ raise
21
+ end
22
+ end
23
+
24
+ module Serializers
25
+ class YardocSerializer < FileSystemSerializer
26
+ def initialize(yfile)
27
+ super(:basepath => yfile, :extension => 'dat')
28
+ end
29
+
30
+ def objects_path; File.join(basepath, 'objects') end
31
+ def proxy_types_path; File.join(basepath, 'proxy_types') end
32
+ def checksums_path; File.join(basepath, 'checksums') end
33
+
34
+ def serialized_path(object)
35
+ path = case object
36
+ when String, Symbol
37
+ object = object.to_s
38
+ if object =~ /#/
39
+ object += '_i'
40
+ elsif object =~ /\./
41
+ object += '_c'
42
+ end
43
+ object.split(/::|\.|#/).map do |p|
44
+ p.gsub(/[^\w\.-]/) do |x|
45
+ encoded = '_'
46
+
47
+ x.each_byte { |b| encoded << ("%X" % b) }
48
+ encoded
49
+ end
50
+ end.join('/') + '.' + extension
51
+ when YARD::CodeObjects::RootObject
52
+ 'root.dat'
53
+ else
54
+ super(object)
55
+ end
56
+ File.join('objects', path)
57
+ end
58
+
59
+ def serialize(object)
60
+ super(object, dump(object))
61
+ end
62
+
63
+ def deserialize(path, is_path = false)
64
+ path = File.join(basepath, serialized_path(path)) unless is_path
65
+ if File.file?(path)
66
+ log.debug "Deserializing #{path}..."
67
+ Marshal.load(File.read(path))
68
+ else
69
+ log.debug "Could not find #{path}"
70
+ nil
71
+ end
72
+ end
73
+
74
+ private
75
+
76
+ def dump(object)
77
+ Marshal.dump(internal_dump(object, true))
78
+ end
79
+
80
+ def internal_dump(object, first_object = false)
81
+ if !first_object && object.is_a?(CodeObjects::Base) &&
82
+ !(Tags::OverloadTag === object)
83
+ return StubProxy.new(object.path, true)
84
+ end
85
+
86
+ if object.is_a?(Hash) || object.is_a?(Array) ||
87
+ object.is_a?(CodeObjects::Base) ||
88
+ object.instance_variables.size > 0
89
+ object = object.dup
90
+ end
91
+
92
+ object.instance_variables.each do |ivar|
93
+ ivar_obj = object.instance_variable_get(ivar)
94
+ ivar_obj_dump = internal_dump(ivar_obj)
95
+ object.instance_variable_set(ivar, ivar_obj_dump)
96
+ end
97
+
98
+ case object
99
+ when Hash
100
+ list = object.map do |k, v|
101
+ [k, v].map {|item| internal_dump(item) }
102
+ end
103
+ object.replace(Hash[list])
104
+ when Array
105
+ list = object.map {|item| internal_dump(item) }
106
+ object.replace(list)
107
+ end
108
+
109
+ object
110
+ end
111
+ end
112
+ end
113
+ end
@@ -46,6 +46,10 @@ module YARD
46
46
  attr_reader :labels
47
47
  attr_accessor :default_factory
48
48
 
49
+ def instance
50
+ @instance ||= new
51
+ end
52
+
49
53
  def default_factory
50
54
  @default_factory ||= DefaultFactory.new
51
55
  end
@@ -19,26 +19,37 @@ module YARD
19
19
  end
20
20
 
21
21
  def name(prefix = false)
22
- object.name(prefix)
22
+ return @name unless prefix
23
+ object.scope == :class ? @name.to_s : "#{object.send(:sep)}#{@name}"
23
24
  end
24
25
 
25
26
  def method_missing(*args, &block)
26
27
  object.send(*args, &block)
27
28
  end
29
+
30
+ def type
31
+ object.type
32
+ end
33
+
34
+ def is_a?(other)
35
+ object.is_a?(other) || self.class >= other.class || false
36
+ end
37
+ alias kind_of? is_a?
28
38
 
29
39
  private
30
40
 
31
41
  def parse_tag(raw_text)
32
- @signature, text = raw_text.split(/\r?\n/, 2)
33
- text ||= ""
42
+ @signature, text = *raw_text.split(/\r?\n/, 2)
34
43
  @signature.strip!
44
+ text ||= ""
35
45
  numspaces = text[/\A(\s*)/, 1].length
36
- text.gsub!(/^[ \t]{#{numspaces}}/, '').strip!
46
+ text.gsub!(/^[ \t]{#{numspaces}}/, '')
47
+ text.strip!
37
48
  @docstring = Docstring.new(text, nil)
38
49
  end
39
50
 
40
51
  def parse_signature
41
- if signature =~ /^(?:def)?\s*(#{CodeObjects::METHODMATCH})(?:(?:\s+|\s*\()(.*)(?:\)\s*$)?)?/m
52
+ if signature =~ /^(?:def\s)?\s*(#{CodeObjects::METHODMATCH})(?:(?:\s+|\s*\()(.*)(?:\)\s*$)?)?/m
42
53
  meth, args = $1, $2
43
54
  meth.gsub!(/\s+/,'')
44
55
  # FIXME refactor this code to not make use of the Handlers::Base class (tokval_list should be moved)
data/lib/yard/tags/tag.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  module YARD
2
2
  module Tags
3
3
  class Tag
4
- attr_reader :tag_name, :text, :types, :name
5
- attr_accessor :object
4
+ attr_accessor :tag_name, :text, :types, :name, :object
6
5
 
7
6
  ##
8
7
  # Creates a new tag object with a tag name and text. Optionally, formally declared types
@@ -8,7 +8,7 @@ module YARD
8
8
  # Registers a new template path in {template_paths}
9
9
  #
10
10
  # @param [String] path a new template path
11
- # @return [nil]
11
+ # @return [void]
12
12
  def register_template_path(path)
13
13
  template_paths.push path
14
14
  end
@@ -86,7 +86,7 @@ module YARD
86
86
  # @param [Array<CodeObjects::Base>] objects a list of {CodeObjects::Base}
87
87
  # objects to pass to the template
88
88
  # @param [Hash] options (see {render})
89
- # @return [nil]
89
+ # @return [void]
90
90
  def generate(objects, options = {})
91
91
  set_default_options(options)
92
92
  options[:objects] = objects
@@ -118,7 +118,7 @@ module YARD
118
118
  # @option options [Symbol] :format (:text) the default format
119
119
  # @option options [Symbol] :type (nil) the :object's type, if provided
120
120
  # @option options [Symbol] :template (:default) the default template
121
- # @return [nil]
121
+ # @return [void]
122
122
  def set_default_options(options = {})
123
123
  options[:format] ||= :text
124
124
  options[:type] ||= options[:object].type if options[:object]
@@ -72,7 +72,7 @@ module YARD
72
72
  #
73
73
  # @todo Refactor into own SimpleMarkup subclass
74
74
  def fix_typewriter(text)
75
- text.gsub(/\+(?! )([^\+]{1,900})(?! )\+/) do
75
+ text.gsub(/\+(?! )([^\n\+]{1,900})(?! )\+/) do
76
76
  '<tt>' + $1.gsub(/(.)/, "\\1\004") + '</tt>'
77
77
  end
78
78
  end
@@ -165,7 +165,7 @@ module YARD
165
165
  return otitle if obj.nil?
166
166
  obj = Registry.resolve(object, obj, true, true) if obj.is_a?(String)
167
167
  title = otitle ? otitle.to_s : h(obj.path)
168
- title = "Top Level Namespace" if title == "" && obj == Registry.root
168
+ title = "Top Level Namespace" if title == "" && obj.root?
169
169
  return title unless serializer
170
170
 
171
171
  return title if obj.is_a?(CodeObjects::Proxy)
@@ -177,13 +177,13 @@ module YARD
177
177
  def link_url(url, title = nil, params = {})
178
178
  params = SymbolHash.new(false).update(
179
179
  :href => url,
180
- :title => title || url
180
+ :title => h(title || url)
181
181
  ).update(params)
182
182
  "<a #{tag_attrs(params)}>#{title}</a>"
183
183
  end
184
184
 
185
185
  def tag_attrs(opts = {})
186
- opts.map {|k,v| "#{k}=#{v.to_s.inspect}" if v }.join(" ")
186
+ opts.sort_by {|k, v| k.to_s }.map {|k,v| "#{k}=#{v.to_s.inspect}" if v }.join(" ")
187
187
  end
188
188
 
189
189
  def anchor_for(object)
@@ -238,30 +238,46 @@ module YARD
238
238
  if filename == options[:readme]
239
239
  filename = 'index'
240
240
  else
241
- filename = 'file.' + File.basename(filename).gsub(/\..+$/, '')
241
+ filename = 'file.' + File.basename(filename).gsub(/\.[^.]+$/, '')
242
242
  end
243
243
  link = File.relative_path(from, filename)
244
244
  link + '.html' + (anchor ? '#' + urlencode(anchor) : '')
245
245
  end
246
246
 
247
247
  def signature(meth, link = true, show_extras = true)
248
- if link
249
- type = (meth.tag(:return) && meth.tag(:return).types ? meth.tag(:return).types.first : nil) || "Object"
250
- type = h(type)
251
- else
252
- arr = meth.tag(:return) ? [(meth.tag(:return).types || []).first].compact : []
253
- arr << "Object" if arr.empty?
254
- type = format_types(arr, false)
248
+ # use first overload tag if it has a return type and method itself does not
249
+ if !meth.tag(:return) && meth.tags(:overload).size == 1 && meth.tag(:overload).tag(:return)
250
+ meth = meth.tag(:overload)
251
+ end
252
+
253
+ type = options[:default_return] || ""
254
+ if meth.tag(:return) && meth.tag(:return).types
255
+ types = meth.tags(:return).map {|t| t.types ? t.types : [] }.flatten
256
+ first = link ? h(types.first) : format_types([types.first], false)
257
+ if types.size == 2 && types.last == 'nil'
258
+ type = first + '<sup>?</sup>'
259
+ elsif types.size == 2 && types.last =~ /^(Array)?<#{Regexp.quote types.first}>$/
260
+ type = first + '<sup>+</sup>'
261
+ elsif types.size > 2
262
+ type = [first, '...'].join(', ')
263
+ elsif types == ['void'] && options[:hide_void_return]
264
+ type = ""
265
+ else
266
+ type = link ? h(types.join(", ")) : format_types(types, false)
267
+ end
268
+ elsif !type.empty?
269
+ type = link ? h(type) : format_types([type], false)
255
270
  end
256
271
 
257
272
  scope = meth.scope == :class ? "+" : "-"
273
+ type = "(#{type}) " unless type.empty?
258
274
  name = meth.name
259
275
  blk = format_block(meth)
260
276
  args = format_args(meth)
261
277
  extras = []
262
278
  extras_text = ''
263
279
  if show_extras
264
- if rw = meth.namespace.attributes[meth.scope][meth.name]
280
+ if meth.is_attribute? && rw = meth.namespace.attributes[meth.scope][meth.name]
265
281
  attname = [rw[:read] ? 'read' : nil, rw[:write] ? 'write' : nil].compact
266
282
  attname = attname.size == 1 ? attname.join('') + 'only' : nil
267
283
  extras << attname if attname
@@ -269,18 +285,36 @@ module YARD
269
285
  extras << meth.visibility if meth.visibility != :public
270
286
  extras_text = ' <span class="extras">(' + extras.join(", ") + ')</span>' unless extras.empty?
271
287
  end
272
- title = "%s (%s) <strong>%s</strong>%s %s" % [scope, type, name, args, blk]
288
+ title = "%s %s<strong>%s</strong>%s %s" % [scope, type, h(name), args, blk]
273
289
  if link
274
290
  if meth.is_a?(YARD::CodeObjects::MethodObject)
275
- link_title = "#{meth.name(true)} (#{meth.scope} #{meth.type})"
291
+ link_title = "#{h meth.name(true)} (#{meth.scope} #{meth.type})"
276
292
  else
277
- link_title = "#{name} (#{meth.type})"
293
+ link_title = "#{h name} (#{meth.type})"
278
294
  end
279
295
  link_url(url_for(meth), title, :title => link_title) + extras_text
280
296
  else
281
297
  title + extras_text
282
298
  end
283
299
  end
300
+
301
+ def html_syntax_highlight(source, type = :ruby)
302
+ return "" unless source
303
+ return source if options[:no_highlight]
304
+
305
+ # handle !!!LANG prefix to send to html_syntax_highlight_LANG
306
+ if source =~ /\A[ \t]*!!!(\w+)[ \t]*\r?\n/
307
+ type, source = $1, $'
308
+ source = $'
309
+ end
310
+
311
+ meth = "html_syntax_highlight_#{type}"
312
+ respond_to?(meth) ? send(meth, source) : h(source)
313
+ end
314
+
315
+ def html_syntax_highlight_plain(source)
316
+ h(source)
317
+ end
284
318
  end
285
319
  end
286
320
  end
@@ -2,9 +2,7 @@ module YARD
2
2
  module Templates
3
3
  module Helpers
4
4
  module HtmlSyntaxHighlightHelper
5
- def html_syntax_highlight(source)
6
- return "" unless source
7
- return source if options[:no_highlight]
5
+ def html_syntax_highlight_ruby(source)
8
6
  tokenlist = Parser::Ruby::RubyParser.parse(source, "(syntax_highlight)").tokens
9
7
  output = ""
10
8
  tokenlist.each do |s|
@@ -2,9 +2,7 @@ module YARD
2
2
  module Templates
3
3
  module Helpers
4
4
  module HtmlSyntaxHighlightHelper
5
- def html_syntax_highlight(source)
6
- return "" unless source
7
- return source if options[:no_highlight]
5
+ def html_syntax_highlight_ruby(source)
8
6
  tokenlist = Parser::Ruby::Legacy::TokenList.new(source)
9
7
  tokenlist.map do |s|
10
8
  prettyclass = s.class.class_name.sub(/^Tk/, '').downcase
@@ -2,6 +2,7 @@ module YARD
2
2
  module Templates::Helpers
3
3
  module MethodHelper
4
4
  def format_args(object)
5
+ return if object.parameters.nil?
5
6
  unless object.parameters.empty?
6
7
  args = object.parameters.map {|n, v| v ? "#{n} = #{v}" : n.to_s }.join(", ")
7
8
  h("(#{args})")
@@ -17,15 +18,21 @@ module YARD
17
18
  end
18
19
 
19
20
  def format_block(object)
20
- if object.has_tag?(:yieldparam)
21
- h "{|" + object.tags(:yieldparam).map {|t| t.name }.join(", ") + "| ... }"
21
+ if object.has_tag?(:yield) && object.tag(:yield).types
22
+ params = object.tag(:yield).types
23
+ elsif object.has_tag?(:yieldparam)
24
+ params = object.tags(:yieldparam).map {|t| t.name }
25
+ elsif object.has_tag?(:yield)
26
+ return "{ ... }"
22
27
  else
23
- ""
28
+ params = nil
24
29
  end
30
+
31
+ params ? h("{|" + params.join(", ") + "| ... }") : ""
25
32
  end
26
33
 
27
34
  def format_lines(object)
28
- return "" unless object.source
35
+ return "" if object.source.nil? || object.line.nil?
29
36
  i = -1
30
37
  object.source.split(/\n/).map { object.line + (i += 1) }.join("\n")
31
38
  end
@@ -37,7 +37,29 @@ module YARD
37
37
  end
38
38
 
39
39
  def signature(meth)
40
- type = (meth.tag(:return) && meth.tag(:return).types ? meth.tag(:return).types.first : nil) || "Object"
40
+ # use first overload tag if it has a return type and method itself does not
41
+ if !meth.tag(:return) && meth.tag(:overload) && meth.tag(:overload).tag(:return)
42
+ meth = meth.tag(:overload)
43
+ end
44
+
45
+ type = options[:default_return] || ""
46
+ if meth.tag(:return) && meth.tag(:return).types
47
+ types = meth.tags(:return).map {|t| t.types ? t.types : [] }.flatten
48
+ first = types.first
49
+ if types.size == 2 && types.last == 'nil'
50
+ type = first + '?'
51
+ elsif types.size == 2 && types.last =~ /^(Array)?<#{Regexp.quote types.first}>$/
52
+ type = first + '+'
53
+ elsif types.size > 2
54
+ type = [first, '...'].join(', ')
55
+ elsif types == ['void'] && options[:hide_void_return]
56
+ type = ""
57
+ else
58
+ type = types.join(", ")
59
+ end
60
+ end
61
+ type = "(#{type})" if type.include?(',')
62
+ type = " -> #{type} " unless type.empty?
41
63
  scope = meth.scope == :class ? "#{meth.namespace.name}." : "#{meth.namespace.name.to_s.downcase}."
42
64
  name = meth.name
43
65
  blk = format_block(meth)
@@ -51,7 +73,7 @@ module YARD
51
73
  end
52
74
  extras << meth.visibility if meth.visibility != :public
53
75
  extras_text = '(' + extras.join(", ") + ')' unless extras.empty?
54
- title = "%s%s%s %s -> %s %s" % [scope, name, args, blk, type, extras_text]
76
+ title = "%s%s%s %s%s%s" % [scope, name, args, blk, type, extras_text]
55
77
  title.gsub(/\s+/, ' ')
56
78
  end
57
79
  end
data/lib/yard/verifier.rb CHANGED
@@ -73,20 +73,20 @@ module YARD
73
73
  # call returns nil, which means users don't need to perform
74
74
  # stringent nil checking
75
75
  #
76
- # @return [nil]
76
+ # @return [void]
77
77
  def modify_nilclass
78
78
  NilClass.send(:define_method, :method_missing) {|*args| }
79
79
  end
80
80
 
81
81
  # Returns the state of NilClass back to normal
82
- # @return [nil]
82
+ # @return [void]
83
83
  def unmodify_nilclass
84
84
  NilClass.send(:undef_method, :method_missing)
85
85
  end
86
86
 
87
87
  # Creates the +__execute+ method by evaluating the expressions
88
88
  # as Ruby code
89
- # @return [nil]
89
+ # @return [void]
90
90
  def create_method_from_expressions(exprs)
91
91
  expr = exprs.flatten.map {|e| "(#{parse_expression(e)})" }.join(" && ")
92
92