yard 0.5.8 → 0.6.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 (211) hide show
  1. data/.yardopts +2 -0
  2. data/ChangeLog +1064 -0
  3. data/README.md +103 -42
  4. data/Rakefile +3 -2
  5. data/benchmarks/parsing.rb +2 -1
  6. data/bin/yard +4 -0
  7. data/bin/yard-graph +1 -1
  8. data/bin/yard-server +4 -0
  9. data/docs/GettingStarted.md +8 -8
  10. data/docs/Handlers.md +5 -5
  11. data/docs/Overview.md +5 -5
  12. data/docs/Parser.md +1 -1
  13. data/docs/Tags.md +1 -1
  14. data/docs/Templates.md +27 -6
  15. data/docs/WhatsNew.md +222 -2
  16. data/lib/rubygems_plugin.rb +1 -0
  17. data/lib/yard.rb +7 -1
  18. data/lib/yard/autoload.rb +46 -6
  19. data/lib/yard/cli/{base.rb → command.rb} +20 -6
  20. data/lib/yard/cli/command_parser.rb +87 -0
  21. data/lib/yard/cli/diff.rb +176 -0
  22. data/lib/yard/cli/gems.rb +74 -0
  23. data/lib/yard/cli/{yard_graph.rb → graph.rb} +9 -8
  24. data/lib/yard/cli/help.rb +18 -0
  25. data/lib/yard/cli/server.rb +137 -0
  26. data/lib/yard/cli/stats.rb +210 -0
  27. data/lib/yard/cli/yardoc.rb +315 -116
  28. data/lib/yard/cli/yri.rb +45 -4
  29. data/lib/yard/code_objects/base.rb +73 -30
  30. data/lib/yard/code_objects/class_object.rb +9 -1
  31. data/lib/yard/code_objects/method_object.rb +11 -0
  32. data/lib/yard/code_objects/namespace_object.rb +8 -2
  33. data/lib/yard/code_objects/proxy.rb +2 -2
  34. data/lib/yard/core_ext/array.rb +3 -49
  35. data/lib/yard/core_ext/file.rb +7 -0
  36. data/lib/yard/core_ext/insertion.rb +60 -0
  37. data/lib/yard/docstring.rb +34 -7
  38. data/lib/yard/globals.rb +2 -2
  39. data/lib/yard/handlers/base.rb +101 -20
  40. data/lib/yard/handlers/processor.rb +23 -7
  41. data/lib/yard/handlers/ruby/alias_handler.rb +1 -0
  42. data/lib/yard/handlers/ruby/attribute_handler.rb +8 -0
  43. data/lib/yard/handlers/ruby/base.rb +71 -2
  44. data/lib/yard/handlers/ruby/class_condition_handler.rb +10 -0
  45. data/lib/yard/handlers/ruby/class_handler.rb +7 -4
  46. data/lib/yard/handlers/ruby/class_variable_handler.rb +1 -0
  47. data/lib/yard/handlers/ruby/constant_handler.rb +1 -0
  48. data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
  49. data/lib/yard/handlers/ruby/extend_handler.rb +2 -3
  50. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +1 -0
  51. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -0
  52. data/lib/yard/handlers/ruby/legacy/base.rb +15 -2
  53. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +5 -0
  54. data/lib/yard/handlers/ruby/legacy/class_handler.rb +7 -4
  55. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +1 -0
  56. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +1 -0
  57. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -0
  58. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -3
  59. data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -3
  60. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +2 -1
  61. data/lib/yard/handlers/ruby/legacy/module_handler.rb +1 -0
  62. data/lib/yard/handlers/ruby/legacy/process_handler.rb +1 -0
  63. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +1 -0
  64. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +1 -0
  65. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -0
  66. data/lib/yard/handlers/ruby/method_handler.rb +5 -1
  67. data/lib/yard/handlers/ruby/mixin_handler.rb +2 -1
  68. data/lib/yard/handlers/ruby/module_handler.rb +1 -0
  69. data/lib/yard/handlers/ruby/process_handler.rb +7 -1
  70. data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -0
  71. data/lib/yard/handlers/ruby/visibility_handler.rb +8 -2
  72. data/lib/yard/handlers/ruby/yield_handler.rb +1 -0
  73. data/lib/yard/logging.rb +7 -1
  74. data/lib/yard/parser/base.rb +1 -0
  75. data/lib/yard/parser/c_parser.rb +2 -0
  76. data/lib/yard/parser/ruby/ast_node.rb +82 -63
  77. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +36 -10
  78. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
  79. data/lib/yard/parser/ruby/legacy/statement.rb +9 -5
  80. data/lib/yard/parser/ruby/legacy/statement_list.rb +20 -11
  81. data/lib/yard/parser/ruby/ruby_parser.rb +18 -1
  82. data/lib/yard/parser/source_parser.rb +6 -1
  83. data/lib/yard/registry.rb +284 -278
  84. data/lib/yard/registry_store.rb +4 -2
  85. data/lib/yard/serializers/base.rb +30 -13
  86. data/lib/yard/serializers/file_system_serializer.rb +10 -1
  87. data/lib/yard/server/adapter.rb +51 -0
  88. data/lib/yard/server/commands/base.rb +98 -0
  89. data/lib/yard/server/commands/display_file_command.rb +20 -0
  90. data/lib/yard/server/commands/display_object_command.rb +50 -0
  91. data/lib/yard/server/commands/frames_command.rb +31 -0
  92. data/lib/yard/server/commands/library_command.rb +83 -0
  93. data/lib/yard/server/commands/library_index_command.rb +23 -0
  94. data/lib/yard/server/commands/list_command.rb +44 -0
  95. data/lib/yard/server/commands/search_command.rb +67 -0
  96. data/lib/yard/server/commands/static_file_command.rb +45 -0
  97. data/lib/yard/server/doc_server_helper.rb +22 -0
  98. data/lib/yard/server/doc_server_serializer.rb +29 -0
  99. data/lib/yard/server/library_version.rb +86 -0
  100. data/lib/yard/server/rack_adapter.rb +38 -0
  101. data/lib/yard/server/router.rb +110 -0
  102. data/lib/yard/server/static_caching.rb +16 -0
  103. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +78 -0
  104. data/lib/yard/server/templates/default/fulldoc/html/images/processing.gif +0 -0
  105. data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +12 -0
  106. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +32 -0
  107. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +46 -0
  108. data/lib/yard/server/templates/default/layout/html/headers.erb +11 -0
  109. data/lib/yard/server/templates/doc_server/frames/html/frames.erb +13 -0
  110. data/lib/yard/server/templates/doc_server/frames/html/setup.rb +3 -0
  111. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +34 -0
  112. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +10 -0
  113. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +13 -0
  114. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +26 -0
  115. data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +12 -0
  116. data/lib/yard/server/templates/doc_server/library_list/html/setup.rb +3 -0
  117. data/lib/yard/server/templates/doc_server/library_list/html/title.erb +2 -0
  118. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +51 -0
  119. data/lib/yard/server/templates/doc_server/processing/html/setup.rb +3 -0
  120. data/lib/yard/server/templates/doc_server/search/html/search.erb +19 -0
  121. data/lib/yard/server/templates/doc_server/search/html/setup.rb +8 -0
  122. data/lib/yard/server/webrick_adapter.rb +38 -0
  123. data/lib/yard/tags/default_factory.rb +0 -5
  124. data/lib/yard/tags/library.rb +61 -22
  125. data/lib/yard/tags/tag.rb +26 -4
  126. data/lib/yard/templates/engine.rb +12 -1
  127. data/lib/yard/templates/erb_cache.rb +2 -1
  128. data/lib/yard/templates/helpers/base_helper.rb +96 -3
  129. data/lib/yard/templates/helpers/filter_helper.rb +5 -0
  130. data/lib/yard/templates/helpers/html_helper.rb +204 -94
  131. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -0
  132. data/lib/yard/templates/helpers/markup_helper.rb +58 -3
  133. data/lib/yard/templates/helpers/method_helper.rb +7 -0
  134. data/lib/yard/templates/helpers/module_helper.rb +5 -0
  135. data/lib/yard/templates/helpers/text_helper.rb +10 -1
  136. data/lib/yard/templates/helpers/uml_helper.rb +13 -0
  137. data/lib/yard/templates/section.rb +106 -0
  138. data/lib/yard/templates/template.rb +20 -19
  139. data/lib/yard/verifier.rb +21 -2
  140. data/spec/cli/command_parser_spec.rb +43 -0
  141. data/spec/cli/diff_spec.rb +170 -0
  142. data/spec/cli/help_spec.rb +22 -0
  143. data/spec/cli/server_spec.rb +140 -0
  144. data/spec/cli/stats_spec.rb +75 -0
  145. data/spec/cli/yardoc_spec.rb +438 -182
  146. data/spec/cli/yri_spec.rb +13 -1
  147. data/spec/code_objects/base_spec.rb +51 -6
  148. data/spec/code_objects/class_object_spec.rb +15 -1
  149. data/spec/code_objects/method_object_spec.rb +29 -0
  150. data/spec/code_objects/namespace_object_spec.rb +150 -129
  151. data/spec/core_ext/array_spec.rb +4 -23
  152. data/spec/core_ext/insertion_spec.rb +37 -0
  153. data/spec/docstring_spec.rb +63 -0
  154. data/spec/handlers/attribute_handler_spec.rb +4 -0
  155. data/spec/handlers/base_spec.rb +98 -26
  156. data/spec/handlers/class_handler_spec.rb +5 -1
  157. data/spec/handlers/examples/attribute_handler_001.rb.txt +5 -0
  158. data/spec/handlers/examples/class_handler_001.rb.txt +4 -0
  159. data/spec/handlers/examples/module_handler_001.rb.txt +6 -1
  160. data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
  161. data/spec/handlers/method_handler_spec.rb +5 -0
  162. data/spec/handlers/module_handler_spec.rb +4 -0
  163. data/spec/handlers/visibility_handler_spec.rb +6 -0
  164. data/spec/parser/source_parser_spec.rb +24 -0
  165. data/spec/registry_spec.rb +44 -8
  166. data/spec/server/adapter_spec.rb +38 -0
  167. data/spec/server/commands/base_spec.rb +87 -0
  168. data/spec/server/commands/static_file_command_spec.rb +67 -0
  169. data/spec/server/doc_server_serializer_spec.rb +58 -0
  170. data/spec/server/router_spec.rb +115 -0
  171. data/spec/server/spec_helper.rb +17 -0
  172. data/spec/server/static_caching_spec.rb +39 -0
  173. data/spec/server/webrick_servlet_spec.rb +20 -0
  174. data/spec/templates/constant_spec.rb +40 -0
  175. data/spec/templates/engine_spec.rb +9 -5
  176. data/spec/templates/examples/class002.html +1 -3
  177. data/spec/templates/examples/constant001.txt +25 -0
  178. data/spec/templates/examples/constant002.txt +7 -0
  179. data/spec/templates/examples/constant003.txt +11 -0
  180. data/spec/templates/examples/module001.txt +1 -1
  181. data/spec/templates/examples/module002.html +319 -0
  182. data/spec/templates/helpers/base_helper_spec.rb +2 -2
  183. data/spec/templates/helpers/html_helper_spec.rb +93 -3
  184. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +5 -0
  185. data/spec/templates/helpers/markup_helper_spec.rb +94 -67
  186. data/spec/templates/helpers/shared_signature_examples.rb +9 -0
  187. data/spec/templates/helpers/text_helper_spec.rb +12 -0
  188. data/spec/templates/module_spec.rb +21 -4
  189. data/spec/templates/section_spec.rb +146 -0
  190. data/spec/templates/template_spec.rb +9 -20
  191. data/templates/default/class/setup.rb +5 -5
  192. data/templates/default/constant/text/header.erb +11 -0
  193. data/templates/default/constant/text/setup.rb +3 -0
  194. data/templates/default/fulldoc/html/css/style.css +29 -3
  195. data/templates/default/fulldoc/html/js/app.js +67 -1
  196. data/templates/default/fulldoc/html/js/full_list.js +3 -8
  197. data/templates/default/fulldoc/html/js/jquery.js +150 -15
  198. data/templates/default/fulldoc/html/setup.rb +9 -0
  199. data/templates/default/layout/html/footer.erb +1 -1
  200. data/templates/default/layout/html/setup.rb +7 -25
  201. data/templates/default/method_details/html/source.erb +1 -1
  202. data/templates/default/module/html/attribute_summary.erb +2 -2
  203. data/templates/default/module/html/method_summary.erb +2 -2
  204. data/templates/default/module/setup.rb +27 -4
  205. data/templates/default/onefile/html/files.erb +5 -0
  206. data/templates/default/onefile/html/layout.erb +22 -0
  207. data/templates/default/onefile/html/readme.erb +3 -0
  208. data/templates/default/onefile/html/setup.rb +40 -0
  209. data/templates/default/root/html/setup.rb +1 -0
  210. data/templates/default/tags/setup.rb +26 -33
  211. metadata +80 -10
@@ -12,16 +12,35 @@ module YARD
12
12
  #
13
13
  # @see Handlers::Base
14
14
  class Processor
15
+
16
+ class << self
17
+ # Registeres a new namespace for handlers of the given type.
18
+ # @since 0.6.0
19
+ def register_handler_namespace(type, ns)
20
+ namespace_for_handler[type] = ns
21
+ end
22
+
23
+ # @return [Hash] a list of registered parser type extensions
24
+ # @private
25
+ # @since 0.6.0
26
+ attr_reader :namespace_for_handler
27
+ undef namespace_for_handler
28
+ def namespace_for_handler; @@parser_type_extensions ||= {} end
29
+ end
30
+
31
+ register_handler_namespace :ruby, Ruby
32
+ register_handler_namespace :ruby18, Ruby::Legacy
33
+
15
34
  # @return [String] the filename
16
35
  attr_accessor :file
17
36
 
18
37
  # @return [CodeObjects::NamespaceObject] the current namespace
19
38
  attr_accessor :namespace
20
39
 
21
- # @return [Symbol] the current visibility
40
+ # @return [Symbol] the current visibility (public, private, protected)
22
41
  attr_accessor :visibility
23
42
 
24
- # @return [Symbol] the current scope
43
+ # @return [Symbol] the current scope (class, instance)
25
44
  attr_accessor :scope
26
45
 
27
46
  # @return [CodeObjects::Base, nil] unlike the namespace, the owner
@@ -33,7 +52,7 @@ module YARD
33
52
  # @return [Boolean] whether or not {Parser::LoadOrderError} is raised
34
53
  attr_accessor :load_order_errors
35
54
 
36
- # @return [Symbol] the parser type (:ruby, :ruby18 or :c)
55
+ # @return [Symbol] the parser type (:ruby, :ruby18, :c)
37
56
  attr_accessor :parser_type
38
57
 
39
58
  # Creates a new Processor for a +file+.
@@ -113,10 +132,7 @@ module YARD
113
132
  # @return [Module] the module containing the handlers depending on
114
133
  # {#parser_type}.
115
134
  def handler_base_namespace
116
- case parser_type
117
- when :ruby; Ruby
118
- when :ruby18; Ruby::Legacy
119
- end
135
+ self.class.namespace_for_handler[parser_type]
120
136
  end
121
137
 
122
138
  # Loads handlers from {#handler_base_namespace}. This ensures that
@@ -1,3 +1,4 @@
1
+ # Handles alias and alias_method calls
1
2
  class YARD::Handlers::Ruby::AliasHandler < YARD::Handlers::Ruby::Base
2
3
  handles :alias, method_call(:alias_method)
3
4
 
@@ -1,3 +1,4 @@
1
+ # Handles +attr_*+ statements in modules/classes
1
2
  class YARD::Handlers::Ruby::AttributeHandler < YARD::Handlers::Ruby::Base
2
3
  handles method_call(:attr)
3
4
  handles method_call(:attr_reader)
@@ -45,6 +46,7 @@ class YARD::Handlers::Ruby::AttributeHandler < YARD::Handlers::Ruby::Base
45
46
  o.source ||= full_src
46
47
  o.signature ||= src
47
48
  o.docstring = statement.comments.to_s.empty? ? doc : statement.comments
49
+ o.visibility = visibility
48
50
  end
49
51
 
50
52
  # Register the objects explicitly
@@ -59,6 +61,12 @@ class YARD::Handlers::Ruby::AttributeHandler < YARD::Handlers::Ruby::Base
59
61
 
60
62
  protected
61
63
 
64
+ # Strips out any non-essential arguments from the attr statement.
65
+ #
66
+ # @param [Array<Parser::Ruby::AstNode>] params a list of the parameters
67
+ # in the attr call.
68
+ # @return [Array<String>] the validated attribute names
69
+ # @raise [Parser::UndocumentableError] if the arguments are not valid.
62
70
  def validated_attribute_names(params)
63
71
  params.map do |obj|
64
72
  case obj.type
@@ -1,10 +1,33 @@
1
1
  module YARD
2
2
  module Handlers
3
3
  module Ruby
4
+ # To implement a custom handler matcher, subclass this class and implement
5
+ # {#matches?} to return whether a node matches the handler.
6
+ #
7
+ # @example A Custom Handler Matcher Extension
8
+ # # Implements a handler that checks for a specific string
9
+ # # in the node's source.
10
+ # class MyExtension < HandlesExtension
11
+ # def matches?(node) node.source.include?(name) end
12
+ # end
13
+ #
14
+ # # This handler will handle any node where the source includes 'foo'
15
+ # class MyHandler < Handlers::Ruby::Base
16
+ # handles MyExtension.new('foo')
17
+ # end
4
18
  class HandlesExtension
19
+ # Creates a new extension with a specific matcher value +name+
20
+ # @param [Object] name the matcher value to check against {#matches?}
5
21
  def initialize(name) @name = name end
22
+
23
+ # Tests if the node matches the handler
24
+ # @param [Parser::Ruby::AstNode] node a Ruby node
25
+ # @return [Boolean] whether the +node+ matches the handler
6
26
  def matches?(node) raise NotImplementedError end
27
+
7
28
  protected
29
+
30
+ # @return [String] the extension matcher value
8
31
  attr_reader :name
9
32
  end
10
33
 
@@ -28,18 +51,62 @@ module YARD
28
51
  def matches?(node) !node.send(name).is_a?(FalseClass) end
29
52
  end
30
53
 
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
56
+ # new-style parser is used. For implementing legacy handlers, see
57
+ # {Legacy::Base}.
58
+ #
59
+ # @abstract See {Handlers::Base} for subclassing information.
60
+ # @see Handlers::Base
61
+ # @see Legacy::Base
31
62
  class Base < Handlers::Base
32
63
  class << self
33
64
  include Parser::Ruby
34
65
 
66
+ # @group Statement Matcher Extensions
67
+
68
+ # Matcher for handling any type of method call. Method calls can
69
+ # be expressed by many {AstNode} types depending on the syntax
70
+ # with which it is called, so YARD allows you to use this matcher
71
+ # to simplify matching a method call.
72
+ #
73
+ # @example Match the "describe" method call
74
+ # handles method_call(:describe)
75
+ #
76
+ # # The following will be matched:
77
+ # # describe(...)
78
+ # # object.describe(...)
79
+ # # describe "argument" do ... end
80
+ #
81
+ # @param [#to_s] name matches the method call of this name
82
+ # @return [void]
35
83
  def method_call(name)
36
84
  MethodCallWrapper.new(name.to_s)
37
85
  end
38
86
 
39
- def meta_type(meth)
40
- TestNodeWrapper.new(meth.to_s + "?")
87
+ # Matcher for handling a node with a specific meta-type. An {AstNode}
88
+ # has a {AstNode#type} to define its type but can also be associated
89
+ # with a set of types. For instance, +:if+ and +:unless+ are both
90
+ # of the meta-type +:condition+.
91
+ #
92
+ # A meta-type is any method on the {AstNode} class ending in "?",
93
+ # though you should not include the "?" suffix in your declaration.
94
+ # Some examples are: "condition", "call", "literal", "kw", "token",
95
+ # "ref".
96
+ #
97
+ # @example Handling any conditional statement (if, unless)
98
+ # handles meta_type(:condition)
99
+ # @param [Symbol] type the meta-type to match. A meta-type can be
100
+ # any method name + "?" that {AstNode} responds to.
101
+ # @return [void]
102
+ def meta_type(type)
103
+ TestNodeWrapper.new(type.to_s + "?")
41
104
  end
42
105
 
106
+ # @group Testing for a Handler
107
+
108
+ # @return [Boolean] whether or not an {AstNode} object should be
109
+ # handled by this handler
43
110
  def handles?(node)
44
111
  handlers.any? do |a_handler|
45
112
  case a_handler
@@ -60,6 +127,8 @@ module YARD
60
127
 
61
128
  include Parser::Ruby
62
129
 
130
+ # @group Parsing an Inner Block
131
+
63
132
  def parse_block(inner_node, opts = {})
64
133
  push_state(opts) do
65
134
  nodes = inner_node.type == :list ? inner_node.children : [inner_node]
@@ -1,3 +1,13 @@
1
+ # Matches if/unless conditions inside classes and attempts to process only
2
+ # one branch (by evaluating the condition if possible).
3
+ #
4
+ # @example A simple class conditional
5
+ # class Foo
6
+ # if 0
7
+ # # This method is ignored
8
+ # def xyz; end
9
+ # end
10
+ # end
1
11
  class YARD::Handlers::Ruby::ClassConditionHandler < YARD::Handlers::Ruby::Base
2
12
  namespace_only
3
13
  handles meta_type(:condition)
@@ -1,3 +1,4 @@
1
+ # Handles class declarations
1
2
  class YARD::Handlers::Ruby::ClassHandler < YARD::Handlers::Ruby::Base
2
3
  include YARD::Handlers::Ruby::StructHandlerMethods
3
4
  namespace_only
@@ -75,15 +76,17 @@ class YARD::Handlers::Ruby::ClassHandler < YARD::Handlers::Ruby::Base
75
76
  end
76
77
 
77
78
  def struct_superclass_name(superclass)
78
- first = superclass.parameters.first
79
- if first.type == :string_literal && first[0].type == :string_content && first[0].size == 1
80
- return "Struct::#{first[0][0][0]}"
79
+ if superclass.call?
80
+ first = superclass.parameters.first
81
+ if first.type == :string_literal && first[0].type == :string_content && first[0].size == 1
82
+ return "Struct::#{first[0][0][0]}"
83
+ end
81
84
  end
82
85
  "Struct"
83
86
  end
84
87
 
85
88
  def parse_struct_superclass(klass, superclass)
86
- return unless superclass.parameters
89
+ return unless superclass.call? && superclass.parameters
87
90
  members = extract_parameters(superclass)
88
91
  create_attributes(klass, members)
89
92
  end
@@ -1,3 +1,4 @@
1
+ # Handles a class variable (@@variable)
1
2
  class YARD::Handlers::Ruby::ClassVariableHandler < YARD::Handlers::Ruby::Base
2
3
  namespace_only
3
4
  handles :assign
@@ -1,3 +1,4 @@
1
+ # Handles any constant assignment
1
2
  class YARD::Handlers::Ruby::ConstantHandler < YARD::Handlers::Ruby::Base
2
3
  namespace_only
3
4
  handles :assign
@@ -1,3 +1,4 @@
1
+ # Handles 'raise' calls inside methods
1
2
  class YARD::Handlers::Ruby::ExceptionHandler < YARD::Handlers::Ruby::Base
2
3
  handles method_call(:raise)
3
4
 
@@ -1,6 +1,5 @@
1
- # `extend` works just like `include` except that it always
2
- # mixes the module in in class scope,
3
- # and that it can handle `extend self`.
1
+ # Handles 'extend' call to include modules into the class scope of another
2
+ # @see MixinHandler
4
3
  class YARD::Handlers::Ruby::ExtendHandler < YARD::Handlers::Ruby::MixinHandler
5
4
  namespace_only
6
5
  handles method_call(:extend)
@@ -1,3 +1,4 @@
1
+ # (see Ruby::AliasHandler)
1
2
  class YARD::Handlers::Ruby::Legacy::AliasHandler < YARD::Handlers::Ruby::Legacy::Base
2
3
  handles /\Aalias(_method)?(\s|\()/
3
4
 
@@ -1,3 +1,4 @@
1
+ # (see Ruby::AttributeHandler)
1
2
  class YARD::Handlers::Ruby::Legacy::AttributeHandler < YARD::Handlers::Ruby::Legacy::Base
2
3
  handles /\Aattr(?:_(?:reader|writer|accessor))?(?:\s|\()/
3
4
 
@@ -44,6 +45,7 @@ class YARD::Handlers::Ruby::Legacy::AttributeHandler < YARD::Handlers::Ruby::Leg
44
45
  o.source ||= full_src
45
46
  o.signature ||= src
46
47
  o.docstring = statement.comments.to_s.empty? ? doc : statement.comments
48
+ o.visibility = visibility
47
49
  end
48
50
 
49
51
  # Register the objects explicitly
@@ -1,10 +1,16 @@
1
1
  module YARD
2
2
  module Handlers
3
3
  module Ruby::Legacy
4
+ # This is the base handler for the legacy parser. To implement a legacy
5
+ # handler, subclass this class.
6
+ #
7
+ # @abstract (see Ruby::Base)
4
8
  class Base < Handlers::Base
5
9
  # For tokens like TkDEF, TkCLASS, etc.
6
10
  include YARD::Parser::Ruby::Legacy::RubyToken
7
11
 
12
+ # @return [Boolean] whether or not a {Parser::Ruby::Legacy::Statement} object should be handled
13
+ # by this handler.
8
14
  def self.handles?(stmt)
9
15
  handlers.any? do |a_handler|
10
16
  case a_handler
@@ -20,6 +26,13 @@ module YARD
20
26
 
21
27
  protected
22
28
 
29
+ # Parses a statement's block with a set of state values. If the
30
+ # statement has no block, nothing happens. A description of state
31
+ # values can be found at {Handlers::Base#push_state}
32
+ #
33
+ # @param [Hash] opts State options
34
+ # @option opts (see Handlers::Base#push_state)
35
+ # @see Handlers::Base#push_state #push_state
23
36
  def parse_block(opts = {})
24
37
  push_state(opts) do
25
38
  if statement.block
@@ -32,8 +45,8 @@ module YARD
32
45
  private
33
46
 
34
47
  # The string value of a token. For example, the return value for the symbol :sym
35
- # would be :sym. The return value for a string "foo #{bar}" would be the literal
36
- # "foo #{bar}" without any interpolation. The return value of the identifier
48
+ # would be :sym. The return value for a string +"foo #{ bar}"+ would be the literal
49
+ # +"foo #{ bar}"+ without any interpolation. The return value of the identifier
37
50
  # 'test' would be the same value: 'test'. Here is a list of common types and
38
51
  # their return values:
39
52
  #
@@ -1,3 +1,5 @@
1
+ # (see Ruby::ClassConditionHandler)
2
+ # @since 0.5.4
1
3
  class YARD::Handlers::Ruby::Legacy::ClassConditionHandler < YARD::Handlers::Ruby::Legacy::Base
2
4
  namespace_only
3
5
  handles TkIF, TkELSIF, TkUNLESS
@@ -22,6 +24,7 @@ class YARD::Handlers::Ruby::Legacy::ClassConditionHandler < YARD::Handlers::Ruby
22
24
  # @return [true, false, nil] true if the condition can be definitely
23
25
  # parsed to true, false if not, and nil if the condition cannot be
24
26
  # parsed with certainty (it's dynamic)
27
+ # @since 0.5.5
25
28
  def parse_condition
26
29
  condition = nil
27
30
 
@@ -60,10 +63,12 @@ class YARD::Handlers::Ruby::Legacy::ClassConditionHandler < YARD::Handlers::Ruby
60
63
  condition
61
64
  end
62
65
 
66
+ # @since 0.5.5
63
67
  def parse_then_block
64
68
  parse_block
65
69
  end
66
70
 
71
+ # @since 0.5.5
67
72
  def parse_else_block
68
73
  stmtlist = YARD::Parser::Ruby::Legacy::StatementList
69
74
  stmtlist.new(statement.block).each do |stmt|
@@ -1,3 +1,4 @@
1
+ # (see Ruby::ClassHandler)
1
2
  class YARD::Handlers::Ruby::Legacy::ClassHandler < YARD::Handlers::Ruby::Legacy::Base
2
3
  include YARD::Handlers::Ruby::StructHandlerMethods
3
4
  handles TkCLASS
@@ -73,10 +74,12 @@ class YARD::Handlers::Ruby::Legacy::ClassHandler < YARD::Handlers::Ruby::Legacy:
73
74
  end
74
75
 
75
76
  def struct_superclass_name(superclass)
76
- paramstring = superclass.match(/\A(Struct)\.new\((.*?)\)/)[2].split(",")
77
- first = paramstring.first.strip
78
- if first[0,1] =~ /['"]/ && first[-1,1] =~ /['"]/ && first !~ /\#\{/
79
- return "Struct::#{first[1..-2]}"
77
+ if match = superclass.match(/\A(Struct)\.new\((.*?)\)/)
78
+ paramstring = match[2].split(",")
79
+ first = paramstring.first.strip
80
+ if first[0,1] =~ /['"]/ && first[-1,1] =~ /['"]/ && first !~ /\#\{/
81
+ return "Struct::#{first[1..-2]}"
82
+ end
80
83
  end
81
84
  "Struct"
82
85
  end
@@ -1,3 +1,4 @@
1
+ # (see Ruby::ClassVariableHandler)
1
2
  class YARD::Handlers::Ruby::Legacy::ClassVariableHandler < YARD::Handlers::Ruby::Legacy::Base
2
3
  HANDLER_MATCH = /\A@@\w+\s*=\s*/m
3
4
  handles HANDLER_MATCH
@@ -1,3 +1,4 @@
1
+ # (see Ruby::ConstantHandler)
1
2
  class YARD::Handlers::Ruby::Legacy::ConstantHandler < YARD::Handlers::Ruby::Legacy::Base
2
3
  HANDLER_MATCH = /\A[A-Z]\w*\s*=[^=]\s*/m
3
4
  handles HANDLER_MATCH
@@ -1,3 +1,4 @@
1
+ # (see Ruby::ExceptionHandler)
1
2
  class YARD::Handlers::Ruby::Legacy::ExceptionHandler < YARD::Handlers::Ruby::Legacy::Base
2
3
  handles /\Araise(\s|\()/
3
4
 
@@ -1,6 +1,4 @@
1
- # `extend` works just like `include` except that it always
2
- # mixes the module in in class scope,
3
- # and that it can handle `extend self`.
1
+ # (see Ruby::ExtendHandler)
4
2
  class YARD::Handlers::Ruby::Legacy::ExtendHandler < YARD::Handlers::Ruby::Legacy::MixinHandler
5
3
  handles /\Aextend(\s|\()/
6
4
 
@@ -1,3 +1,4 @@
1
+ # (see Ruby::MethodHandler)
1
2
  class YARD::Handlers::Ruby::Legacy::MethodHandler < YARD::Handlers::Ruby::Legacy::Base
2
3
  handles TkDEF
3
4
 
@@ -13,11 +14,14 @@ class YARD::Handlers::Ruby::Legacy::MethodHandler < YARD::Handlers::Ruby::Legacy
13
14
  else
14
15
  raise YARD::Parser::UndocumentableError, "method: invalid name"
15
16
  end
16
-
17
+
17
18
  # Class method if prefixed by self(::|.) or Module(::|.)
18
19
  if meth =~ /(?:#{NSEPQ}|#{CSEPQ})([^#{NSEP}#{CSEPQ}]+)$/
19
- mscope, meth = :class, $1
20
- nobj = P(namespace, $`) unless $` == "self"
20
+ mscope, meth, prefix = :class, $1, $`
21
+ if prefix =~ /^[a-z]/ && prefix != "self"
22
+ raise YARD::Parser::UndocumentableError, 'method defined on object instance'
23
+ end
24
+ nobj = P(namespace, prefix) unless prefix == "self"
21
25
  end
22
26
 
23
27
  obj = register MethodObject.new(nobj, meth, mscope) do |o|
@@ -1,3 +1,4 @@
1
+ # (see Ruby::MixinHandler)
1
2
  class YARD::Handlers::Ruby::Legacy::MixinHandler < YARD::Handlers::Ruby::Legacy::Base
2
3
  handles /\Ainclude(\s|\()/
3
4
 
@@ -23,6 +24,6 @@ class YARD::Handlers::Ruby::Legacy::MixinHandler < YARD::Handlers::Ruby::Legacy:
23
24
  obj = Proxy.new(namespace, obj.value)
24
25
  end
25
26
 
26
- namespace.mixins(scope) << obj
27
+ namespace.mixins(scope).unshift(obj) unless namespace.mixins(scope).include?(obj)
27
28
  end
28
29
  end