yard 0.6.8 → 0.7.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 (224) hide show
  1. data/.yardopts +1 -0
  2. data/ChangeLog +723 -0
  3. data/README.md +16 -6
  4. data/docs/CodeObjects.md +10 -16
  5. data/docs/GettingStarted.md +232 -32
  6. data/docs/Glossary.md +1 -2
  7. data/docs/Handlers.md +10 -16
  8. data/docs/Overview.md +14 -13
  9. data/docs/Parser.md +13 -22
  10. data/docs/Tags.md +209 -16
  11. data/docs/Templates.md +237 -26
  12. data/docs/WhatsNew.md +178 -2
  13. data/lib/yard.rb +13 -10
  14. data/lib/yard/autoload.rb +22 -18
  15. data/lib/yard/cli/command.rb +13 -12
  16. data/lib/yard/cli/command_parser.rb +20 -19
  17. data/lib/yard/cli/config.rb +19 -19
  18. data/lib/yard/cli/diff.rb +46 -21
  19. data/lib/yard/cli/gems.rb +11 -11
  20. data/lib/yard/cli/graph.rb +13 -13
  21. data/lib/yard/cli/help.rb +1 -1
  22. data/lib/yard/cli/list.rb +22 -0
  23. data/lib/yard/cli/server.rb +17 -17
  24. data/lib/yard/cli/stats.rb +32 -32
  25. data/lib/yard/cli/yardoc.rb +181 -135
  26. data/lib/yard/cli/yri.rb +29 -29
  27. data/lib/yard/code_objects/base.rb +101 -101
  28. data/lib/yard/code_objects/class_object.rb +20 -20
  29. data/lib/yard/code_objects/constant_object.rb +1 -1
  30. data/lib/yard/code_objects/extended_method_object.rb +5 -5
  31. data/lib/yard/code_objects/extra_file_object.rb +89 -0
  32. data/lib/yard/code_objects/macro_object.rb +215 -0
  33. data/lib/yard/code_objects/method_object.rb +30 -30
  34. data/lib/yard/code_objects/module_object.rb +1 -1
  35. data/lib/yard/code_objects/namespace_object.rb +39 -39
  36. data/lib/yard/code_objects/proxy.rb +38 -38
  37. data/lib/yard/code_objects/root_object.rb +1 -1
  38. data/lib/yard/config.rb +40 -40
  39. data/lib/yard/core_ext/array.rb +2 -2
  40. data/lib/yard/core_ext/file.rb +11 -11
  41. data/lib/yard/core_ext/insertion.rb +10 -10
  42. data/lib/yard/core_ext/module.rb +2 -2
  43. data/lib/yard/core_ext/string.rb +2 -2
  44. data/lib/yard/core_ext/symbol_hash.rb +14 -14
  45. data/lib/yard/docstring.rb +122 -54
  46. data/lib/yard/globals.rb +2 -2
  47. data/lib/yard/handlers/base.rb +216 -127
  48. data/lib/yard/handlers/processor.rb +65 -27
  49. data/lib/yard/handlers/ruby/alias_handler.rb +6 -3
  50. data/lib/yard/handlers/ruby/attribute_handler.rb +7 -6
  51. data/lib/yard/handlers/ruby/base.rb +50 -31
  52. data/lib/yard/handlers/ruby/class_condition_handler.rb +11 -11
  53. data/lib/yard/handlers/ruby/class_handler.rb +10 -10
  54. data/lib/yard/handlers/ruby/class_variable_handler.rb +3 -3
  55. data/lib/yard/handlers/ruby/constant_handler.rb +7 -7
  56. data/lib/yard/handlers/ruby/exception_handler.rb +2 -2
  57. data/lib/yard/handlers/ruby/extend_handler.rb +1 -1
  58. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +8 -5
  59. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +6 -5
  60. data/lib/yard/handlers/ruby/legacy/base.rb +42 -27
  61. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +9 -9
  62. data/lib/yard/handlers/ruby/legacy/class_handler.rb +13 -12
  63. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +3 -6
  64. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +5 -8
  65. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -1
  66. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -0
  67. data/lib/yard/handlers/ruby/legacy/macro_handler.rb +40 -0
  68. data/lib/yard/handlers/ruby/legacy/method_handler.rb +10 -10
  69. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +4 -3
  70. data/lib/yard/handlers/ruby/legacy/module_handler.rb +2 -1
  71. data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +4 -4
  72. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +2 -1
  73. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +3 -3
  74. data/lib/yard/handlers/ruby/macro_handler.rb +41 -0
  75. data/lib/yard/handlers/ruby/macro_handler_methods.rb +130 -0
  76. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -1
  77. data/lib/yard/handlers/ruby/method_handler.rb +13 -13
  78. data/lib/yard/handlers/ruby/mixin_handler.rb +4 -4
  79. data/lib/yard/handlers/ruby/module_handler.rb +2 -1
  80. data/lib/yard/handlers/ruby/private_constant_handler.rb +4 -4
  81. data/lib/yard/handlers/ruby/struct_handler_methods.rb +11 -11
  82. data/lib/yard/handlers/ruby/visibility_handler.rb +1 -1
  83. data/lib/yard/handlers/ruby/yield_handler.rb +5 -5
  84. data/lib/yard/logging.rb +11 -11
  85. data/lib/yard/parser/base.rb +8 -8
  86. data/lib/yard/parser/c_parser.rb +42 -33
  87. data/lib/yard/parser/ruby/ast_node.rb +62 -61
  88. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +66 -66
  89. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +4 -4
  90. data/lib/yard/parser/ruby/legacy/statement.rb +11 -11
  91. data/lib/yard/parser/ruby/legacy/statement_list.rb +15 -15
  92. data/lib/yard/parser/ruby/legacy/token_list.rb +9 -9
  93. data/lib/yard/parser/ruby/ruby_parser.rb +51 -37
  94. data/lib/yard/parser/source_parser.rb +271 -46
  95. data/lib/yard/rake/yardoc_task.rb +18 -17
  96. data/lib/yard/registry.rb +64 -64
  97. data/lib/yard/registry_store.rb +34 -34
  98. data/lib/yard/rubygems/backports.rb +8 -0
  99. data/lib/yard/rubygems/backports/LICENSE.txt +57 -0
  100. data/lib/yard/rubygems/backports/MIT.txt +20 -0
  101. data/lib/yard/rubygems/backports/gem.rb +8 -0
  102. data/lib/yard/rubygems/backports/source_index.rb +353 -0
  103. data/lib/yard/rubygems/specification.rb +2 -2
  104. data/lib/yard/serializers/base.rb +20 -20
  105. data/lib/yard/serializers/file_system_serializer.rb +28 -24
  106. data/lib/yard/serializers/process_serializer.rb +3 -3
  107. data/lib/yard/serializers/stdout_serializer.rb +6 -6
  108. data/lib/yard/serializers/yardoc_serializer.rb +17 -17
  109. data/lib/yard/server/adapter.rb +12 -12
  110. data/lib/yard/server/commands/base.rb +26 -26
  111. data/lib/yard/server/commands/display_file_command.rb +3 -2
  112. data/lib/yard/server/commands/display_object_command.rb +5 -5
  113. data/lib/yard/server/commands/frames_command.rb +1 -1
  114. data/lib/yard/server/commands/library_command.rb +7 -7
  115. data/lib/yard/server/commands/library_index_command.rb +2 -2
  116. data/lib/yard/server/commands/list_command.rb +8 -8
  117. data/lib/yard/server/commands/search_command.rb +8 -8
  118. data/lib/yard/server/commands/static_file_command.rb +3 -3
  119. data/lib/yard/server/doc_server_helper.rb +6 -3
  120. data/lib/yard/server/doc_server_serializer.rb +1 -1
  121. data/lib/yard/server/library_version.rb +45 -45
  122. data/lib/yard/server/rack_adapter.rb +10 -10
  123. data/lib/yard/server/router.rb +28 -28
  124. data/lib/yard/server/static_caching.rb +5 -5
  125. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +3 -3
  126. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +1 -1
  127. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +2 -2
  128. data/lib/yard/server/templates/default/layout/html/headers.erb +13 -8
  129. data/lib/yard/server/templates/default/layout/html/setup.rb +7 -0
  130. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +2 -2
  131. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +14 -4
  132. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +2 -2
  133. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +2 -2
  134. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +1 -1
  135. data/lib/yard/server/templates/doc_server/search/html/search.erb +1 -1
  136. data/lib/yard/server/webrick_adapter.rb +2 -2
  137. data/lib/yard/tags/default_factory.rb +19 -19
  138. data/lib/yard/tags/default_tag.rb +1 -1
  139. data/lib/yard/tags/library.rb +68 -63
  140. data/lib/yard/tags/option_tag.rb +1 -1
  141. data/lib/yard/tags/overload_tag.rb +9 -9
  142. data/lib/yard/tags/ref_tag_list.rb +2 -2
  143. data/lib/yard/tags/tag.rb +7 -7
  144. data/lib/yard/templates/engine.rb +31 -31
  145. data/lib/yard/templates/erb_cache.rb +1 -1
  146. data/lib/yard/templates/helpers/base_helper.rb +46 -32
  147. data/lib/yard/templates/helpers/filter_helper.rb +2 -2
  148. data/lib/yard/templates/helpers/html_helper.rb +120 -81
  149. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -4
  150. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +9 -9
  151. data/lib/yard/templates/helpers/markup_helper.rb +37 -30
  152. data/lib/yard/templates/helpers/method_helper.rb +7 -7
  153. data/lib/yard/templates/helpers/text_helper.rb +7 -7
  154. data/lib/yard/templates/helpers/uml_helper.rb +3 -3
  155. data/lib/yard/templates/section.rb +14 -14
  156. data/lib/yard/templates/template.rb +54 -54
  157. data/lib/yard/verifier.rb +27 -27
  158. data/spec/cli/list_spec.rb +8 -0
  159. data/spec/cli/yardoc_spec.rb +58 -10
  160. data/spec/code_objects/extra_file_object_spec.rb +132 -0
  161. data/spec/code_objects/macro_object_spec.rb +154 -0
  162. data/spec/docstring_spec.rb +90 -0
  163. data/spec/handlers/base_spec.rb +22 -0
  164. data/spec/handlers/examples/macro_handler_001.rb.txt +73 -0
  165. data/spec/handlers/examples/method_handler_001.rb.txt +17 -0
  166. data/spec/handlers/macro_handler_spec.rb +140 -0
  167. data/spec/handlers/method_handler_spec.rb +28 -0
  168. data/spec/handlers/processor_spec.rb +4 -0
  169. data/spec/handlers/spec_helper.rb +1 -1
  170. data/spec/parser/c_parser_spec.rb +47 -16
  171. data/spec/parser/examples/extrafile.c.txt +8 -0
  172. data/spec/parser/examples/multifile.c.txt +6 -0
  173. data/spec/parser/ruby/ruby_parser_spec.rb +5 -0
  174. data/spec/parser/source_parser_spec.rb +235 -0
  175. data/spec/rake/yardoc_task_spec.rb +22 -17
  176. data/spec/serializers/file_system_serializer_spec.rb +6 -0
  177. data/spec/server/commands/library_command_spec.rb +39 -0
  178. data/spec/spec_helper.rb +14 -0
  179. data/spec/templates/examples/method001.html +6 -6
  180. data/spec/templates/examples/method002.html +4 -4
  181. data/spec/templates/examples/method003.html +10 -10
  182. data/spec/templates/examples/method005.html +2 -2
  183. data/spec/templates/examples/module001.dot +2 -0
  184. data/spec/templates/examples/module001.html +76 -37
  185. data/spec/templates/examples/module001.txt +1 -1
  186. data/spec/templates/helpers/base_helper_spec.rb +7 -2
  187. data/spec/templates/helpers/html_helper_spec.rb +49 -5
  188. data/spec/templates/helpers/markup_helper_spec.rb +9 -8
  189. data/spec/templates/module_spec.rb +7 -0
  190. data/spec/templates/onefile_spec.rb +47 -0
  191. data/templates/default/fulldoc/html/css/style.css +7 -5
  192. data/templates/default/fulldoc/html/full_list.erb +13 -10
  193. data/templates/default/fulldoc/html/full_list_files.erb +1 -1
  194. data/templates/default/fulldoc/html/js/app.js +16 -14
  195. data/templates/default/fulldoc/html/js/full_list.js +7 -6
  196. data/templates/default/fulldoc/html/setup.rb +78 -17
  197. data/templates/default/layout/html/files.erb +1 -1
  198. data/templates/default/layout/html/headers.erb +11 -7
  199. data/templates/default/layout/html/search.erb +4 -4
  200. data/templates/default/layout/html/setup.rb +28 -8
  201. data/templates/default/module/html/inherited_attributes.erb +17 -0
  202. data/templates/default/module/setup.rb +1 -1
  203. data/templates/default/onefile/html/files.erb +2 -2
  204. data/templates/default/onefile/html/layout.erb +1 -1
  205. data/templates/default/onefile/html/setup.rb +7 -5
  206. data/templates/default/tags/html/option.erb +1 -1
  207. data/templates/default/tags/html/tag.erb +3 -3
  208. data/templates/guide/class/html/setup.rb +1 -0
  209. data/templates/guide/docstring/html/setup.rb +1 -0
  210. data/templates/guide/fulldoc/html/css/style.css +91 -0
  211. data/templates/guide/fulldoc/html/js/app.js +33 -0
  212. data/templates/guide/fulldoc/html/setup.rb +54 -0
  213. data/templates/guide/layout/html/layout.erb +81 -0
  214. data/templates/guide/layout/html/setup.rb +24 -0
  215. data/templates/guide/method/html/header.erb +18 -0
  216. data/templates/guide/method/html/setup.rb +21 -0
  217. data/templates/guide/module/html/header.erb +7 -0
  218. data/templates/guide/module/html/method_list.erb +5 -0
  219. data/templates/guide/module/html/setup.rb +26 -0
  220. data/templates/guide/tags/html/setup.rb +8 -0
  221. metadata +40 -7
  222. data/lib/yard/handlers/ruby/legacy/process_handler.rb +0 -13
  223. data/lib/yard/handlers/ruby/process_handler.rb +0 -18
  224. data/spec/handlers/process_handler_spec.rb +0 -17
@@ -2,7 +2,8 @@
2
2
  class YARD::Handlers::Ruby::Legacy::ClassHandler < YARD::Handlers::Ruby::Legacy::Base
3
3
  include YARD::Handlers::Ruby::StructHandlerMethods
4
4
  handles TkCLASS
5
-
5
+ namespace_only
6
+
6
7
  process do
7
8
  if statement.tokens.to_s =~ /^class\s+(#{NAMESPACEMATCH})\s*(?:<\s*(.+)|\Z)/m
8
9
  classname = $1
@@ -25,14 +26,14 @@ class YARD::Handlers::Ruby::Legacy::ClassHandler < YARD::Handlers::Ruby::Legacy:
25
26
  create_attributes(klass, members_from_tags(klass))
26
27
  end
27
28
  parse_block(:namespace => klass)
28
-
29
+
29
30
  if undocsuper
30
31
  raise YARD::Parser::UndocumentableError, 'superclass (class was added without superclass)'
31
32
  end
32
33
  elsif statement.tokens.to_s =~ /^class\s*<<\s*([\w\:]+)/
33
34
  classname = $1
34
35
  proxy = Proxy.new(namespace, classname)
35
-
36
+
36
37
  # Allow constants to reference class names
37
38
  if ConstantObject === proxy
38
39
  if proxy.value =~ /\A#{NAMESPACEMATCH}\Z/
@@ -41,10 +42,10 @@ class YARD::Handlers::Ruby::Legacy::ClassHandler < YARD::Handlers::Ruby::Legacy:
41
42
  raise YARD::Parser::UndocumentableError, "constant class reference '#{classname}'"
42
43
  end
43
44
  end
44
-
45
+
45
46
  if classname == "self"
46
47
  parse_block(:namespace => namespace, :scope => :class)
47
- elsif classname[0,1] =~ /[A-Z]/
48
+ elsif classname[0,1] =~ /[A-Z]/
48
49
  register ClassObject.new(namespace, classname) if Proxy === proxy
49
50
  parse_block(:namespace => proxy, :scope => :class)
50
51
  else
@@ -54,9 +55,9 @@ class YARD::Handlers::Ruby::Legacy::ClassHandler < YARD::Handlers::Ruby::Legacy:
54
55
  raise YARD::Parser::UndocumentableError, "class: #{statement.tokens}"
55
56
  end
56
57
  end
57
-
58
+
58
59
  private
59
-
60
+
60
61
  # Extracts the parameter list from the Struct.new declaration and returns it
61
62
  # formatted as a list of member names. Expects the user will have used symbols
62
63
  # to define the struct member names
@@ -67,7 +68,7 @@ class YARD::Handlers::Ruby::Legacy::ClassHandler < YARD::Handlers::Ruby::Legacy:
67
68
  paramstring = superstring.match(/\A(O?Struct)\.new\((.*?)\)/)[2]
68
69
  paramstring.split(",").select {|x| x.strip[0,1] == ":"}.map {|x| x.strip[1..-1] } # the 1..-1 chops the leading :
69
70
  end
70
-
71
+
71
72
  def create_struct_superclass(superclass, superclass_def)
72
73
  return if superclass == "Struct"
73
74
  the_super = register ClassObject.new(P("Struct"), superclass[8..-1]) do |o|
@@ -76,7 +77,7 @@ class YARD::Handlers::Ruby::Legacy::ClassHandler < YARD::Handlers::Ruby::Legacy:
76
77
  parse_struct_subclass(the_super, superclass_def)
77
78
  the_super
78
79
  end
79
-
80
+
80
81
  def struct_superclass_name(superclass)
81
82
  if match = superclass.match(/\A(Struct)\.new\((.*?)\)/)
82
83
  paramstring = match[2].split(",")
@@ -87,17 +88,17 @@ class YARD::Handlers::Ruby::Legacy::ClassHandler < YARD::Handlers::Ruby::Legacy:
87
88
  end
88
89
  "Struct"
89
90
  end
90
-
91
+
91
92
  def parse_struct_subclass(klass, superclass_def)
92
93
  # Bounce if there's no parens
93
94
  return unless superclass_def =~ /O?Struct\.new\((.*?)\)/
94
95
  members = extract_parameters(superclass_def)
95
96
  create_attributes(klass, members)
96
97
  end
97
-
98
+
98
99
  def parse_superclass(superclass)
99
100
  case superclass
100
- when /\A(#{NAMESPACEMATCH})(?:\s|\Z)/,
101
+ when /\A(#{NAMESPACEMATCH})(?:\s|\Z)/,
101
102
  /\A(Struct|OStruct)\.new/,
102
103
  /\ADelegateClass\((.+?)\)\s*\Z/,
103
104
  /\A(#{NAMESPACEMATCH})\(/
@@ -2,14 +2,11 @@
2
2
  class YARD::Handlers::Ruby::Legacy::ClassVariableHandler < YARD::Handlers::Ruby::Legacy::Base
3
3
  HANDLER_MATCH = /\A@@\w+\s*=\s*/m
4
4
  handles HANDLER_MATCH
5
-
5
+ namespace_only
6
+
6
7
  process do
7
- # Don't document @@cvars if they're set in second class objects (methods) because
8
- # they're not "static" when executed from a method
9
- return unless owner.is_a? NamespaceObject
10
-
11
8
  name, value = *statement.tokens.to_s.split(/\s*=\s*/, 2)
12
- register ClassVariableObject.new(namespace, name) do |o|
9
+ register ClassVariableObject.new(namespace, name) do |o|
13
10
  o.source = statement
14
11
  o.value = value.strip
15
12
  end
@@ -3,12 +3,9 @@ class YARD::Handlers::Ruby::Legacy::ConstantHandler < YARD::Handlers::Ruby::Lega
3
3
  include YARD::Handlers::Ruby::StructHandlerMethods
4
4
  HANDLER_MATCH = /\A[A-Z]\w*\s*=[^=]\s*/m
5
5
  handles HANDLER_MATCH
6
-
6
+ namespace_only
7
+
7
8
  process do
8
- # Don't document CONSTANTS if they're set in second class objects (methods) because
9
- # they're not "static" when executed from a method
10
- return unless owner.is_a? NamespaceObject
11
-
12
9
  name, value = *statement.tokens.to_s.split(/\s*=\s*/, 2)
13
10
  if value =~ /\A\s*Struct.new(?:\s*\(?|\b)/
14
11
  process_structclass(name, $')
@@ -16,14 +13,14 @@ class YARD::Handlers::Ruby::Legacy::ConstantHandler < YARD::Handlers::Ruby::Lega
16
13
  register ConstantObject.new(namespace, name) {|o| o.source = statement; o.value = value.strip }
17
14
  end
18
15
  end
19
-
16
+
20
17
  private
21
-
18
+
22
19
  def process_structclass(classname, parameters)
23
20
  klass = create_class(classname, P(:Struct))
24
21
  create_attributes(klass, extract_parameters(parameters))
25
22
  end
26
-
23
+
27
24
  def extract_parameters(parameters)
28
25
  members = tokval_list(YARD::Parser::Ruby::Legacy::TokenList.new(parameters), TkSYMBOL)
29
26
  members.map {|m| m.to_s }
@@ -1,7 +1,7 @@
1
1
  # (see Ruby::ExceptionHandler)
2
2
  class YARD::Handlers::Ruby::Legacy::ExceptionHandler < YARD::Handlers::Ruby::Legacy::Base
3
3
  handles /\Araise(\s|\()/
4
-
4
+
5
5
  process do
6
6
  return unless owner.is_a?(MethodObject) # Only methods yield
7
7
  return if owner.has_tag?(:raise)
@@ -1,6 +1,7 @@
1
1
  # (see Ruby::ExtendHandler)
2
2
  class YARD::Handlers::Ruby::Legacy::ExtendHandler < YARD::Handlers::Ruby::Legacy::MixinHandler
3
3
  handles /\Aextend(\s|\()/
4
+ namespace_only
4
5
 
5
6
  def scope; :class end
6
7
 
@@ -0,0 +1,40 @@
1
+ module YARD
2
+ module Handlers
3
+ module Ruby
4
+ module Legacy
5
+ # (see Ruby::MacroHandler)
6
+ class MacroHandler < Base
7
+ include CodeObjects
8
+ include MacroHandlerMethods
9
+ handles TkIDENTIFIER
10
+ namespace_only
11
+
12
+ process do
13
+ return if namespace == Registry.root
14
+ globals.__attached_macros ||= {}
15
+ if !globals.__attached_macros[caller_method]
16
+ return if Ruby::MacroHandler::IGNORE_METHODS[caller_method]
17
+ return if !statement.comments || statement.comments.empty?
18
+ end
19
+
20
+ comments = statement.comments ? statement.comments.join("\n") : ""
21
+ @macro, @docstring = nil, Docstring.new(comments)
22
+ find_or_create_macro(@docstring)
23
+ return if !@macro && !statement.comments_hash_flag && @docstring.tags.size == 0
24
+ @docstring = expanded_macro_or_docstring
25
+ name = method_name
26
+ raise UndocumentableError, "method, missing name" if name.nil? || name.empty?
27
+ tmp_scope = sanitize_scope
28
+ tmp_vis = sanitize_visibility
29
+ object = MethodObject.new(namespace, name, tmp_scope)
30
+ register(object)
31
+ object.visibility = tmp_vis
32
+ object.dynamic = true
33
+ object.signature = method_signature
34
+ create_attribute_data(object)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,7 +1,7 @@
1
1
  # (see Ruby::MethodHandler)
2
2
  class YARD::Handlers::Ruby::Legacy::MethodHandler < YARD::Handlers::Ruby::Legacy::Base
3
3
  handles TkDEF
4
-
4
+
5
5
  process do
6
6
  nobj = namespace
7
7
  mscope = scope
@@ -23,27 +23,27 @@ class YARD::Handlers::Ruby::Legacy::MethodHandler < YARD::Handlers::Ruby::Legacy
23
23
  end
24
24
  nobj = P(namespace, prefix) unless prefix == "self"
25
25
  end
26
-
26
+
27
27
  nobj = P(namespace, nobj.value) while nobj.type == :constant
28
- obj = register MethodObject.new(nobj, meth, mscope) do |o|
29
- o.visibility = visibility
28
+ obj = register MethodObject.new(nobj, meth, mscope) do |o|
29
+ o.visibility = visibility
30
30
  o.source = statement
31
31
  o.explicit = true
32
32
  o.parameters = args
33
33
  end
34
-
34
+
35
35
  # delete any aliases referencing old method
36
36
  nobj.aliases.each do |aobj, name|
37
37
  next unless name == obj.name
38
38
  nobj.aliases.delete(aobj)
39
39
  end if nobj.is_a?(NamespaceObject)
40
-
40
+
41
41
  if mscope == :instance && meth == "initialize"
42
42
  unless obj.has_tag?(:return)
43
- obj.docstring.add_tag(YARD::Tags::Tag.new(:return,
43
+ obj.docstring.add_tag(YARD::Tags::Tag.new(:return,
44
44
  "a new instance of #{namespace.name}", namespace.name.to_s))
45
45
  end
46
- elsif mscope == :class && obj.docstring.blank? && %w(inherited included
46
+ elsif mscope == :class && obj.docstring.blank? && %w(inherited included
47
47
  extended method_added method_removed method_undefined).include?(meth)
48
48
  obj.docstring.add_tag(YARD::Tags::Tag.new(:private, nil))
49
49
  elsif meth.to_s =~ /\?$/
@@ -53,7 +53,7 @@ class YARD::Handlers::Ruby::Legacy::MethodHandler < YARD::Handlers::Ruby::Legacy
53
53
  obj.docstring.add_tag(YARD::Tags::Tag.new(:return, "", "Boolean"))
54
54
  end
55
55
  end
56
-
56
+
57
57
  if obj.has_tag?(:option)
58
58
  # create the options parameter if its missing
59
59
  obj.tags(:option).each do |option|
@@ -64,7 +64,7 @@ class YARD::Handlers::Ruby::Legacy::MethodHandler < YARD::Handlers::Ruby::Legacy
64
64
  end
65
65
  end
66
66
  end
67
-
67
+
68
68
  if info = obj.attr_info
69
69
  if meth.to_s =~ /=$/ # writer
70
70
  info[:write] = obj if info[:read]
@@ -1,7 +1,8 @@
1
1
  # (see Ruby::MixinHandler)
2
2
  class YARD::Handlers::Ruby::Legacy::MixinHandler < YARD::Handlers::Ruby::Legacy::Base
3
3
  handles /\Ainclude(\s|\()/
4
-
4
+ namespace_only
5
+
5
6
  process do
6
7
  errors = []
7
8
  statement.tokens[1..-1].to_s.split(/\s*,\s*/).each do |mixin|
@@ -12,7 +13,7 @@ class YARD::Handlers::Ruby::Legacy::MixinHandler < YARD::Handlers::Ruby::Legacy:
12
13
  errors << err.message
13
14
  end
14
15
  end
15
-
16
+
16
17
  if errors.size > 0
17
18
  msg = errors.size == 1 ? ": #{errors[0]}" : "s: #{errors.join(", ")}"
18
19
  raise YARD::Parser::UndocumentableError, "mixin#{msg} for class #{namespace.path}"
@@ -27,7 +28,7 @@ class YARD::Handlers::Ruby::Legacy::MixinHandler < YARD::Handlers::Ruby::Legacy:
27
28
  end
28
29
 
29
30
  obj = Proxy.new(namespace, mixmatch)
30
-
31
+
31
32
  case obj
32
33
  when Proxy
33
34
  obj.type = :module
@@ -1,7 +1,8 @@
1
1
  # (see Ruby::ModuleHandler)
2
2
  class YARD::Handlers::Ruby::Legacy::ModuleHandler < YARD::Handlers::Ruby::Legacy::Base
3
3
  handles TkMODULE
4
-
4
+ namespace_only
5
+
5
6
  process do
6
7
  modname = statement.tokens.to_s[/^module\s+(#{NAMESPACEMATCH})/, 1]
7
8
  mod = register ModuleObject.new(namespace, modname)
@@ -1,16 +1,16 @@
1
1
  # (see Ruby::PrivateConstantHandler)
2
2
  class YARD::Handlers::Ruby::Legacy::PrivateConstantHandler < YARD::Handlers::Ruby::Legacy::Base
3
- namespace_only
4
3
  handles /\Aprivate_constant(\s|\(|$)/
5
-
4
+ namespace_only
5
+
6
6
  process do
7
7
  tokval_list(statement.tokens[2..-1], :attr, TkCONSTANT).each do |name|
8
8
  privatize_constant name
9
9
  end
10
10
  end
11
-
11
+
12
12
  private
13
-
13
+
14
14
  def privatize_constant(name)
15
15
  const = Proxy.new(namespace, name)
16
16
  ensure_loaded!(const)
@@ -1,7 +1,8 @@
1
1
  # (see Ruby::VisibilityHandler)
2
2
  class YARD::Handlers::Ruby::Legacy::VisibilityHandler < YARD::Handlers::Ruby::Legacy::Base
3
3
  handles /\A(protected|private|public)(\s|\(|$)/
4
-
4
+ namespace_only
5
+
5
6
  process do
6
7
  vis = statement.tokens.first.text
7
8
  if statement.tokens.size == 1
@@ -1,7 +1,7 @@
1
1
  # (see Ruby::YieldHandler)
2
2
  class YARD::Handlers::Ruby::Legacy::YieldHandler < YARD::Handlers::Ruby::Legacy::Base
3
3
  handles TkYIELD
4
-
4
+
5
5
  process do
6
6
  return unless owner.is_a?(MethodObject) # Only methods yield
7
7
  return if owner.has_tag? :yield # Don't override yield tags
@@ -12,11 +12,11 @@ class YARD::Handlers::Ruby::Legacy::YieldHandler < YARD::Handlers::Ruby::Legacy:
12
12
  item = item.inspect unless item.is_a?(String)
13
13
  if item == "self"
14
14
  yieldtag.types << '_self'
15
- owner.docstring.add_tag YARD::Tags::Tag.new(:yieldparam,
15
+ owner.docstring.add_tag YARD::Tags::Tag.new(:yieldparam,
16
16
  "the object that the method was called on", owner.namespace.path, '_self')
17
17
  elsif item == "super"
18
18
  yieldtag.types << '_super'
19
- owner.docstring.add_tag YARD::Tags::Tag.new(:yieldparam,
19
+ owner.docstring.add_tag YARD::Tags::Tag.new(:yieldparam,
20
20
  "the result of the method from the superclass", nil, '_super')
21
21
  else
22
22
  yieldtag.types << item
@@ -0,0 +1,41 @@
1
+ module YARD
2
+ module Handlers
3
+ module Ruby
4
+ # Handles a macro (dsl-style method)
5
+ class MacroHandler < Base
6
+ include CodeObjects
7
+ include MacroHandlerMethods
8
+ handles method_call
9
+ namespace_only
10
+
11
+ IGNORE_METHODS = Hash[*%w(alias alias_method autoload attr attr_accessor
12
+ attr_reader attr_writer extend include public private protected
13
+ private_constant).map {|n| [n, true] }.flatten]
14
+
15
+ process do
16
+ return if namespace == Registry.root
17
+ globals.__attached_macros ||= {}
18
+ if !globals.__attached_macros[caller_method]
19
+ return if IGNORE_METHODS[caller_method]
20
+ return if !statement.comments || statement.comments.empty?
21
+ end
22
+
23
+ @macro, @docstring = nil, Docstring.new(statement.comments)
24
+ find_or_create_macro(@docstring)
25
+ return if !@macro && !statement.comments_hash_flag && @docstring.tags.size == 0
26
+ @docstring = expanded_macro_or_docstring
27
+ name = method_name
28
+ raise UndocumentableError, "method, missing name" if name.nil? || name.empty?
29
+ tmp_scope = sanitize_scope
30
+ tmp_vis = sanitize_visibility
31
+ object = MethodObject.new(namespace, name, tmp_scope)
32
+ register(object)
33
+ object.visibility = tmp_vis
34
+ object.dynamic = true
35
+ object.signature = method_signature
36
+ create_attribute_data(object)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,130 @@
1
+ module YARD
2
+ module Handlers
3
+ module Ruby
4
+ module MacroHandlerMethods
5
+ include CodeObjects
6
+ include Parser
7
+
8
+ def find_or_create_macro(docstring)
9
+ return @macro if @macro
10
+ return if @macro = super(docstring)
11
+
12
+ # Look for implicit macros
13
+ (globals.__attached_macros[caller_method] || []).each do |macro|
14
+ namespace.inheritance_tree.each do |obj|
15
+ break(@macro = macro) if obj == macro.method_object.namespace
16
+ end
17
+ end
18
+ end
19
+
20
+ def expanded_macro_or_docstring
21
+ return @docstring unless @macro
22
+ all_params = ([caller_method] + call_params).compact
23
+ data = MacroObject.apply_macro(@macro, @docstring, all_params, statement.source)
24
+ Docstring.new(data)
25
+ end
26
+
27
+ def expand_macro(object, macro)
28
+ if @docstring
29
+ object.docstring = @docstring
30
+ object.docstring.tags.each do |tag|
31
+ tag.object = object if tag.respond_to?(:object=)
32
+ end
33
+ else
34
+ super(object, macro)
35
+ end
36
+ end
37
+
38
+ def sanitize_scope
39
+ tmp_scope = @docstring.tag(:scope) ? @docstring.tag(:scope).text : ''
40
+ %w(class instance).include?(tmp_scope) ? tmp_scope.to_sym : scope
41
+ end
42
+
43
+ def sanitize_visibility
44
+ vis = @docstring.tag(:visibility) ? @docstring.tag(:visibility).text : ''
45
+ %w(public protected private).include?(vis) ? vis.to_sym : visibility
46
+ end
47
+
48
+ def create_attribute_data(object)
49
+ return unless object.docstring.tag(:attribute)
50
+ ensure_loaded!(namespace)
51
+ clean_name = object.name.to_s.sub(/=$/, '')
52
+ namespace.attributes[object.scope][clean_name] ||= SymbolHash[:read => nil, :write => nil]
53
+ if attribute_readable?
54
+ namespace.attributes[object.scope][clean_name][:read] = object
55
+ end
56
+ if attribute_writable?
57
+ if object.name.to_s[-1,1] == '='
58
+ writer = object
59
+ else
60
+ writer = MethodObject.new(namespace, object.name.to_s + '=', object.scope)
61
+ register(writer)
62
+ writer.signature = "def #{object.name}=(value)"
63
+ writer.visibility = object.visibility
64
+ writer.dynamic = true
65
+ end
66
+ namespace.attributes[object.scope][clean_name][:write] = writer
67
+ end
68
+ end
69
+
70
+ def method_name
71
+ name = nil
72
+ [:method, :attribute, :overload].each do |tag_name|
73
+ if tag = @docstring.tag(tag_name)
74
+ name = tag.send(tag == :overload ? :text : :name).to_s
75
+ if tag_name == :method && name =~ /\(|\s/
76
+ overload = Tags::OverloadTag.new(:overload, name)
77
+ @docstring.add_tag(overload)
78
+ end
79
+ break
80
+ end
81
+ end
82
+ name = nil if name =~ /\A\s*\Z/
83
+ name ||= call_params.first
84
+ return unless name
85
+ if name =~ /\A\s*([^\(; \t]+)/
86
+ name = $1
87
+ end
88
+ if @docstring.tag(:attribute) && !attribute_readable?
89
+ name = name + '='
90
+ end
91
+ name
92
+ end
93
+
94
+ def method_signature
95
+ if @docstring.tag(:method)
96
+ name = @docstring.tag(:method).name
97
+ elsif @docstring.tag(:overload)
98
+ name = @docstring.tag(:overload).signature
99
+ elsif @docstring.tag(:attribute)
100
+ name = @docstring.tag(:attribute).text
101
+ name += '=(value)' if !attribute_readable?
102
+ else
103
+ name = method_name
104
+ end
105
+ name = nil if name =~ /\A\s*\Z/
106
+ name ||= call_params.first
107
+ name =~ /^def\b/ ? name : "def #{name}"
108
+ end
109
+
110
+ private
111
+
112
+ def attribute_writable?
113
+ if @docstring.tag(:attribute)
114
+ types = @docstring.tag(:attribute).types
115
+ return types ? types.join.include?('w') : true
116
+ end
117
+ false
118
+ end
119
+
120
+ def attribute_readable?
121
+ if @docstring.tag(:attribute)
122
+ types = @docstring.tag(:attribute).types
123
+ return types ? (types.join =~ /(?!w)r/ ? true : false) : true
124
+ end
125
+ false
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end