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
@@ -1,15 +1,20 @@
1
+ require 'ostruct'
2
+
1
3
  module YARD
2
4
  module Handlers
3
- # Iterates over all statements in a file and delegates them to the
5
+ # Iterates over all statements in a file and delegates them to the
4
6
  # {Handlers::Base} objects that are registered to handle the statement.
5
- #
7
+ #
6
8
  # This class is passed to each handler and keeps overall processing state.
7
9
  # For example, if the {#visibility} is set in a handler, all following
8
- # statements will have access to this state. This allows "public",
10
+ # statements will have access to this state. This allows "public",
9
11
  # "protected" and "private" statements to be handled in classes and modules.
10
12
  # In addition, the {#namespace} can be set during parsing to control
11
- # where objects are being created from.
12
- #
13
+ # where objects are being created from. You can also access extra stateful
14
+ # properties that any handler can set during the duration of the post
15
+ # processing of a file from {#extra_state}. If you need to access state
16
+ # across different files, look at {#globals}.
17
+ #
13
18
  # @see Handlers::Base
14
19
  class Processor
15
20
 
@@ -36,37 +41,68 @@ module YARD
36
41
 
37
42
  # @return [CodeObjects::NamespaceObject] the current namespace
38
43
  attr_accessor :namespace
39
-
44
+
40
45
  # @return [Symbol] the current visibility (public, private, protected)
41
46
  attr_accessor :visibility
42
-
47
+
43
48
  # @return [Symbol] the current scope (class, instance)
44
49
  attr_accessor :scope
45
-
50
+
46
51
  # @return [CodeObjects::Base, nil] unlike the namespace, the owner
47
52
  # is a non-namespace object that should be stored between statements.
48
53
  # For instance, when parsing a method body, the {CodeObjects::MethodObject}
49
54
  # is set as the owner, in case any extra method information is processed.
50
55
  attr_accessor :owner
51
-
56
+
52
57
  # @return [Boolean] whether or not {Parser::LoadOrderError} is raised
53
58
  attr_accessor :load_order_errors
54
-
59
+
55
60
  # @return [Symbol] the parser type (:ruby, :ruby18, :c)
56
61
  attr_accessor :parser_type
57
62
 
58
- # Creates a new Processor for a +file+.
63
+ # Handlers can share state for the entire post processing stage through
64
+ # this attribute. Note that post processing stage spans multiple files.
65
+ # To share state only within a single file, use {#extra_state}
59
66
  #
67
+ # @example Sharing state among two handlers
68
+ # class Handler1 < YARD::Handlers::Ruby::Base
69
+ # handles :class
70
+ # process { globals.foo = :bar }
71
+ # end
72
+ #
73
+ # class Handler2 < YARD::Handlers::Ruby::Base
74
+ # handles :method
75
+ # process { puts globals.foo }
76
+ # end
77
+ # @return [OpenStruct] global shared state for post-processing stage
78
+ # @see #extra_state
79
+ attr_accessor :globals
80
+
81
+ # Share state across different handlers inside of a file.
82
+ # This attribute is similar to {#visibility}, {#scope}, {#namespace}
83
+ # and {#owner}, in that they all maintain state across all handlers
84
+ # for the entire source file. Use this attribute to store any data
85
+ # your handler might need to save during the parsing of a file. If
86
+ # you need to save state across files, see {#globals}.
87
+ #
88
+ # @return [OpenStruct] an open structure that can store arbitrary data
89
+ # @see #globals
90
+ attr_accessor :extra_state
91
+
92
+ # Creates a new Processor for a +file+.
93
+ #
60
94
  # @param [String] file the name of the file that is being processed.
61
- # uses '(stdin)' if file is nil.
95
+ # uses '(stdin)' if file is nil.
62
96
  # @param [Boolean] load_order_error whether or not to raise {Parser::LoadOrderError}
63
97
  # when a file has unresolved references that need to be parsed first.
64
- # If these errors are raised, the processor will attempt to load all
98
+ # If these errors are raised, the processor will attempt to load all
65
99
  # other files before continuing to parse the file.
66
100
  # @param [Symbol] parser_type the parser type (:ruby, :ruby18, :c) from
67
101
  # the parser. Used to select the handler (since handlers are specific
68
102
  # to a parser type).
69
- def initialize(file = nil, load_order_errors = false, parser_type = Parser::SourceParser.parser_type)
103
+ # @param [OpenStruct] globals the object holding all state during the
104
+ # post processing stage
105
+ def initialize(file = nil, load_order_errors = false, parser_type = Parser::SourceParser.parser_type, globals = nil)
70
106
  @file = file || "(stdin)"
71
107
  @namespace = YARD::Registry.root
72
108
  @visibility = :public
@@ -75,26 +111,28 @@ module YARD
75
111
  @load_order_errors = load_order_errors
76
112
  @parser_type = parser_type
77
113
  @handlers_loaded = {}
114
+ @globals = globals || OpenStruct.new
115
+ @extra_state = OpenStruct.new
78
116
  load_handlers
79
117
  end
80
-
118
+
81
119
  # Processes a list of statements by finding handlers to process each
82
120
  # one.
83
- #
121
+ #
84
122
  # @param [Array] statements a list of statements
85
- # @return [void]
123
+ # @return [void]
86
124
  def process(statements)
87
125
  statements.each_with_index do |stmt, index|
88
- find_handlers(stmt).each do |handler|
126
+ find_handlers(stmt).each do |handler|
89
127
  begin
90
128
  handler.new(self, stmt).process
91
129
  rescue Parser::LoadOrderError => loaderr
92
130
  raise # Pass this up
93
131
  rescue NamespaceMissingError => missingerr
94
- log.warn "The #{missingerr.object.type} #{missingerr.object.path} has not yet been recognized."
95
- log.warn "If this class/method is part of your source tree, this will affect your documentation results."
132
+ log.warn "The #{missingerr.object.type} #{missingerr.object.path} has not yet been recognized."
133
+ log.warn "If this class/method is part of your source tree, this will affect your documentation results."
96
134
  log.warn "You can correct this issue by loading the source file for this object before `#{file}'"
97
- log.warn
135
+ log.warn
98
136
  rescue Parser::UndocumentableError => undocerr
99
137
  log.warn "in #{handler.to_s}: Undocumentable #{undocerr.message}"
100
138
  log.warn "\tin file '#{file}':#{stmt.line}:\n\n" + stmt.show + "\n"
@@ -106,9 +144,9 @@ module YARD
106
144
  end
107
145
  end
108
146
  end
109
-
147
+
110
148
  # Searches for all handlers in {Base.subclasses} that match the +statement+
111
- #
149
+ #
112
150
  # @param statement the statement object to match.
113
151
  # @return [Array<Base>] a list of handlers to process the statement with.
114
152
  def find_handlers(statement)
@@ -118,9 +156,9 @@ module YARD
118
156
  handler.matches_file?(file) && handler.handles?(statement)
119
157
  end
120
158
  end
121
-
159
+
122
160
  private
123
-
161
+
124
162
  # Returns the handler base class
125
163
  # @return [Base] the base class
126
164
  def handler_base_class
@@ -128,13 +166,13 @@ module YARD
128
166
  end
129
167
 
130
168
  # The module holding the handlers to be loaded
131
- #
169
+ #
132
170
  # @return [Module] the module containing the handlers depending on
133
171
  # {#parser_type}.
134
172
  def handler_base_namespace
135
173
  self.class.namespace_for_handler[parser_type]
136
174
  end
137
-
175
+
138
176
  # Loads handlers from {#handler_base_namespace}. This ensures that
139
177
  # Ruby1.9 handlers are never loaded into 1.8; also lowers the amount
140
178
  # of modules that are loaded
@@ -1,7 +1,8 @@
1
1
  # Handles alias and alias_method calls
2
2
  class YARD::Handlers::Ruby::AliasHandler < YARD::Handlers::Ruby::Base
3
3
  handles :alias, method_call(:alias_method)
4
-
4
+ namespace_only
5
+
5
6
  process do
6
7
  names = []
7
8
  if statement.type == :alias
@@ -17,7 +18,7 @@ class YARD::Handlers::Ruby::AliasHandler < YARD::Handlers::Ruby::Base
17
18
  end
18
19
  end
19
20
  raise YARD::Parser::UndocumentableError, "alias/alias_method" if names.size != 2
20
-
21
+
21
22
  new_meth, old_meth = names[0].to_sym, names[1].to_sym
22
23
  old_obj = namespace.child(:name => old_meth, :scope => scope)
23
24
  new_obj = register MethodObject.new(namespace, new_meth, scope) do |o|
@@ -30,11 +31,13 @@ class YARD::Handlers::Ruby::AliasHandler < YARD::Handlers::Ruby::Base
30
31
  new_obj.signature = old_obj.signature
31
32
  new_obj.source = old_obj.source
32
33
  new_obj.docstring = old_obj.docstring + YARD::Docstring.new(statement.comments)
34
+ new_obj.docstring.line_range = statement.comments_range
35
+ new_obj.docstring.hash_flag = statement.comments_hash_flag
33
36
  new_obj.docstring.object = new_obj
34
37
  else
35
38
  new_obj.signature = "def #{new_meth}" # this is all we know.
36
39
  end
37
-
40
+
38
41
  namespace.aliases[new_obj] = old_meth
39
42
  end
40
43
  end
@@ -4,12 +4,13 @@ class YARD::Handlers::Ruby::AttributeHandler < YARD::Handlers::Ruby::Base
4
4
  handles method_call(:attr_reader)
5
5
  handles method_call(:attr_writer)
6
6
  handles method_call(:attr_accessor)
7
-
7
+ namespace_only
8
+
8
9
  process do
9
10
  return if statement.type == :var_ref
10
11
  read, write = true, false
11
12
  params = statement.parameters(false).dup
12
-
13
+
13
14
  # Change read/write based on attr_reader/writer/accessor
14
15
  case statement.method_name(true)
15
16
  when :attr
@@ -28,7 +29,7 @@ class YARD::Handlers::Ruby::AttributeHandler < YARD::Handlers::Ruby::Base
28
29
  # Add all attributes
29
30
  validated_attribute_names(params).each do |name|
30
31
  namespace.attributes[scope][name] ||= SymbolHash[:read => nil, :write => nil]
31
-
32
+
32
33
  # Show their methods as well
33
34
  {:read => name, :write => "#{name}="}.each do |type, meth|
34
35
  if (type == :read ? read : write)
@@ -58,11 +59,11 @@ class YARD::Handlers::Ruby::AttributeHandler < YARD::Handlers::Ruby::Base
58
59
  end
59
60
  end
60
61
  end
61
-
62
+
62
63
  protected
63
-
64
+
64
65
  # Strips out any non-essential arguments from the attr statement.
65
- #
66
+ #
66
67
  # @param [Array<Parser::Ruby::AstNode>] params a list of the parameters
67
68
  # in the attr call.
68
69
  # @return [Array<String>] the validated attribute names
@@ -3,97 +3,97 @@ module YARD
3
3
  module Ruby
4
4
  # To implement a custom handler matcher, subclass this class and implement
5
5
  # {#matches?} to return whether a node matches the handler.
6
- #
6
+ #
7
7
  # @example A Custom Handler Matcher Extension
8
8
  # # Implements a handler that checks for a specific string
9
9
  # # in the node's source.
10
10
  # class MyExtension < HandlesExtension
11
11
  # def matches?(node) node.source.include?(name) end
12
12
  # end
13
- #
13
+ #
14
14
  # # This handler will handle any node where the source includes 'foo'
15
15
  # class MyHandler < Handlers::Ruby::Base
16
- # handles MyExtension.new('foo')
16
+ # handles MyExtension.new('foo')
17
17
  # end
18
18
  class HandlesExtension
19
19
  # Creates a new extension with a specific matcher value +name+
20
20
  # @param [Object] name the matcher value to check against {#matches?}
21
21
  def initialize(name) @name = name end
22
-
22
+
23
23
  # Tests if the node matches the handler
24
24
  # @param [Parser::Ruby::AstNode] node a Ruby node
25
25
  # @return [Boolean] whether the +node+ matches the handler
26
26
  def matches?(node) raise NotImplementedError end
27
-
27
+
28
28
  protected
29
-
29
+
30
30
  # @return [String] the extension matcher value
31
31
  attr_reader :name
32
32
  end
33
-
33
+
34
34
  class MethodCallWrapper < HandlesExtension
35
35
  def matches?(node)
36
36
  case node.type
37
37
  when :var_ref
38
38
  if !node.parent || node.parent.type == :list
39
- return true if node[0].type == :ident && node[0][0] == name
39
+ return true if node[0].type == :ident && (name.nil? || node[0][0] == name)
40
40
  end
41
41
  when :fcall, :command
42
- return true if node[0][0] == name
42
+ return true if name.nil? || node[0][0] == name
43
43
  when :call, :command_call
44
- return true if node[2][0] == name
44
+ return true if name.nil? || node[2][0] == name
45
45
  end
46
46
  false
47
47
  end
48
48
  end
49
-
49
+
50
50
  class TestNodeWrapper < HandlesExtension
51
51
  def matches?(node) !node.send(name).is_a?(FalseClass) end
52
52
  end
53
-
53
+
54
54
  # This is the base handler class for the new-style (1.9) Ruby parser.
55
- # All handlers that subclass this base class will be used when the
55
+ # All handlers that subclass this base class will be used when the
56
56
  # new-style parser is used. For implementing legacy handlers, see
57
57
  # {Legacy::Base}.
58
- #
58
+ #
59
59
  # @abstract See {Handlers::Base} for subclassing information.
60
60
  # @see Handlers::Base
61
61
  # @see Legacy::Base
62
62
  class Base < Handlers::Base
63
63
  class << self
64
64
  include Parser::Ruby
65
-
65
+
66
66
  # @group Statement Matcher Extensions
67
-
67
+
68
68
  # Matcher for handling any type of method call. Method calls can
69
69
  # be expressed by many {AstNode} types depending on the syntax
70
70
  # with which it is called, so YARD allows you to use this matcher
71
71
  # to simplify matching a method call.
72
- #
72
+ #
73
73
  # @example Match the "describe" method call
74
74
  # handles method_call(:describe)
75
- #
75
+ #
76
76
  # # The following will be matched:
77
77
  # # describe(...)
78
78
  # # object.describe(...)
79
79
  # # describe "argument" do ... end
80
- #
80
+ #
81
81
  # @param [#to_s] name matches the method call of this name
82
82
  # @return [void]
83
- def method_call(name)
84
- MethodCallWrapper.new(name.to_s)
83
+ def method_call(name = nil)
84
+ MethodCallWrapper.new(name ? name.to_s : nil)
85
85
  end
86
-
86
+
87
87
  # Matcher for handling a node with a specific meta-type. An {AstNode}
88
88
  # has a {AstNode#type} to define its type but can also be associated
89
89
  # with a set of types. For instance, +:if+ and +:unless+ are both
90
90
  # of the meta-type +:condition+.
91
- #
92
- # A meta-type is any method on the {AstNode} class ending in "?",
91
+ #
92
+ # A meta-type is any method on the {AstNode} class ending in "?",
93
93
  # though you should not include the "?" suffix in your declaration.
94
94
  # Some examples are: "condition", "call", "literal", "kw", "token",
95
95
  # "ref".
96
- #
96
+ #
97
97
  # @example Handling any conditional statement (if, unless)
98
98
  # handles meta_type(:condition)
99
99
  # @param [Symbol] type the meta-type to match. A meta-type can be
@@ -102,14 +102,14 @@ module YARD
102
102
  def meta_type(type)
103
103
  TestNodeWrapper.new(type.to_s + "?")
104
104
  end
105
-
105
+
106
106
  # @group Testing for a Handler
107
-
107
+
108
108
  # @return [Boolean] whether or not an {AstNode} object should be
109
109
  # handled by this handler
110
110
  def handles?(node)
111
- handlers.any? do |a_handler|
112
- case a_handler
111
+ handlers.any? do |a_handler|
112
+ case a_handler
113
113
  when Symbol
114
114
  a_handler == node.type
115
115
  when String
@@ -126,15 +126,34 @@ module YARD
126
126
  end
127
127
 
128
128
  include Parser::Ruby
129
-
129
+
130
130
  # @group Parsing an Inner Block
131
-
131
+
132
132
  def parse_block(inner_node, opts = {})
133
133
  push_state(opts) do
134
134
  nodes = inner_node.type == :list ? inner_node.children : [inner_node]
135
135
  parser.process(nodes)
136
136
  end
137
137
  end
138
+
139
+ # @group Macro Handling
140
+
141
+ def call_params
142
+ return [] unless statement.respond_to?(:parameters)
143
+ statement.parameters(false).map do |param|
144
+ param.jump(:ident, :tstring_content).source
145
+ end
146
+ end
147
+
148
+ def caller_method
149
+ if statement.call?
150
+ statement.method_name(true).to_s
151
+ elsif statement.type == :var_ref
152
+ statement[0].jump(:ident).source
153
+ else
154
+ nil
155
+ end
156
+ end
138
157
  end
139
158
  end
140
159
  end
@@ -1,6 +1,6 @@
1
1
  # Matches if/unless conditions inside classes and attempts to process only
2
2
  # one branch (by evaluating the condition if possible).
3
- #
3
+ #
4
4
  # @example A simple class conditional
5
5
  # class Foo
6
6
  # if 0
@@ -9,9 +9,9 @@
9
9
  # end
10
10
  # end
11
11
  class YARD::Handlers::Ruby::ClassConditionHandler < YARD::Handlers::Ruby::Base
12
- namespace_only
13
12
  handles meta_type(:condition)
14
-
13
+ namespace_only
14
+
15
15
  process do
16
16
  condition = parse_condition
17
17
  if condition == nil
@@ -24,24 +24,24 @@ class YARD::Handlers::Ruby::ClassConditionHandler < YARD::Handlers::Ruby::Base
24
24
  parse_else_block
25
25
  end
26
26
  end
27
-
27
+
28
28
  protected
29
-
29
+
30
30
  # Parses the condition part of the if/unless statement
31
- #
31
+ #
32
32
  # @return [true, false, nil] true if the condition can be definitely
33
33
  # parsed to true, false if not, and nil if the condition cannot be
34
34
  # parsed with certainty (it's dynamic)
35
35
  def parse_condition
36
36
  condition = nil
37
-
37
+
38
38
  # Right now we can handle very simple unary conditions like:
39
39
  # if true
40
40
  # if false
41
41
  # if 0
42
42
  # if 100 (not 0)
43
43
  # if defined? SOME_CONSTANT
44
- #
44
+ #
45
45
  # The last case will do a lookup in the registry and then one
46
46
  # in the Ruby world (using eval).
47
47
  case statement.condition.type
@@ -66,18 +66,18 @@ class YARD::Handlers::Ruby::ClassConditionHandler < YARD::Handlers::Ruby::Base
66
66
  condition = false
67
67
  end
68
68
  end
69
-
69
+
70
70
  # Invert an unless condition
71
71
  if statement.type == :unless || statement.type == :unless_mod
72
72
  condition = !condition if condition != nil
73
73
  end
74
74
  condition
75
75
  end
76
-
76
+
77
77
  def parse_then_block
78
78
  parse_block(statement.then_block)
79
79
  end
80
-
80
+
81
81
  def parse_else_block
82
82
  parse_block(statement.else_block) if statement.else_block
83
83
  end