yard 0.8.7.6 → 0.9.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 (225) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -1
  3. data/LICENSE +2 -2
  4. data/README.md +2 -2
  5. data/Rakefile +1 -1
  6. data/bin/yard +0 -0
  7. data/bin/yardoc +0 -0
  8. data/bin/yri +0 -0
  9. data/docs/GettingStarted.md +88 -6
  10. data/docs/images/handlers-class-diagram.png +0 -0
  11. data/docs/images/overview-class-diagram.png +0 -0
  12. data/docs/images/parser-class-diagram.png +0 -0
  13. data/docs/templates/default/fulldoc/html/full_list_tag.erb +6 -4
  14. data/lib/yard/autoload.rb +3 -0
  15. data/lib/yard/cli/yardoc.rb +1 -1
  16. data/lib/yard/code_objects/base.rb +4 -1
  17. data/lib/yard/code_objects/extra_file_object.rb +3 -1
  18. data/lib/yard/code_objects/proxy.rb +2 -2
  19. data/lib/yard/docstring.rb +11 -6
  20. data/lib/yard/handlers/base.rb +1 -2
  21. data/lib/yard/handlers/c/base.rb +19 -0
  22. data/lib/yard/handlers/c/handler_methods.rb +42 -8
  23. data/lib/yard/handlers/c/init_handler.rb +1 -1
  24. data/lib/yard/handlers/c/method_handler.rb +3 -3
  25. data/lib/yard/handlers/ruby/decorator_handler_methods.rb +132 -0
  26. data/lib/yard/handlers/ruby/legacy/private_class_method_handler.rb +1 -1
  27. data/lib/yard/handlers/ruby/private_class_method_handler.rb +6 -39
  28. data/lib/yard/handlers/ruby/private_constant_handler.rb +36 -30
  29. data/lib/yard/handlers/ruby/public_class_method_handler.rb +13 -0
  30. data/lib/yard/handlers/ruby/struct_handler_methods.rb +1 -0
  31. data/lib/yard/handlers/ruby/visibility_handler.rb +5 -8
  32. data/lib/yard/logging.rb +1 -0
  33. data/lib/yard/parser/ruby/ruby_parser.rb +2 -2
  34. data/lib/yard/parser/source_parser.rb +6 -6
  35. data/lib/yard/rake/yardoc_task.rb +2 -2
  36. data/lib/yard/serializers/file_system_serializer.rb +33 -1
  37. data/lib/yard/server/commands/display_file_command.rb +8 -3
  38. data/lib/yard/server/commands/display_object_command.rb +7 -3
  39. data/lib/yard/server/doc_server_helper.rb +2 -8
  40. data/lib/yard/server/doc_server_serializer.rb +2 -4
  41. data/lib/yard/server/router.rb +1 -1
  42. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +57 -8
  43. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +2 -10
  44. data/lib/yard/server/templates/default/layout/html/script_setup.erb +1 -2
  45. data/lib/yard/server/templates/default/method_details/html/permalink.erb +3 -3
  46. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +4 -4
  47. data/lib/yard/tags/directives.rb +1 -0
  48. data/lib/yard/tags/library.rb +9 -7
  49. data/lib/yard/tags/overload_tag.rb +4 -1
  50. data/lib/yard/templates/helpers/html_helper.rb +4 -3
  51. data/lib/yard/templates/template_options.rb +3 -0
  52. data/lib/yard/version.rb +1 -1
  53. data/spec/cli/command_parser_spec.rb +14 -14
  54. data/spec/cli/command_spec.rb +11 -11
  55. data/spec/cli/config_spec.rb +32 -32
  56. data/spec/cli/diff_spec.rb +86 -90
  57. data/spec/cli/display_spec.rb +6 -6
  58. data/spec/cli/gems_spec.rb +28 -28
  59. data/spec/cli/graph_spec.rb +8 -8
  60. data/spec/cli/help_spec.rb +8 -8
  61. data/spec/cli/i18n_spec.rb +33 -37
  62. data/spec/cli/list_spec.rb +2 -2
  63. data/spec/cli/markup_types_spec.rb +3 -3
  64. data/spec/cli/server_spec.rb +74 -88
  65. data/spec/cli/stats_spec.rb +14 -14
  66. data/spec/cli/yardoc_spec.rb +316 -321
  67. data/spec/cli/yri_spec.rb +45 -45
  68. data/spec/code_objects/base_spec.rb +174 -173
  69. data/spec/code_objects/class_object_spec.rb +65 -65
  70. data/spec/code_objects/code_object_list_spec.rb +13 -11
  71. data/spec/code_objects/constants_spec.rb +68 -58
  72. data/spec/code_objects/extra_file_object_spec.rb +71 -59
  73. data/spec/code_objects/macro_object_spec.rb +64 -64
  74. data/spec/code_objects/method_object_spec.rb +80 -72
  75. data/spec/code_objects/module_object_spec.rb +47 -47
  76. data/spec/code_objects/namespace_object_spec.rb +51 -51
  77. data/spec/code_objects/proxy_spec.rb +54 -54
  78. data/spec/config_spec.rb +104 -104
  79. data/spec/core_ext/array_spec.rb +5 -5
  80. data/spec/core_ext/file_spec.rb +33 -33
  81. data/spec/core_ext/hash_spec.rb +5 -5
  82. data/spec/core_ext/insertion_spec.rb +18 -18
  83. data/spec/core_ext/module_spec.rb +6 -6
  84. data/spec/core_ext/string_spec.rb +17 -17
  85. data/spec/core_ext/symbol_hash_spec.rb +42 -39
  86. data/spec/docstring_parser_spec.rb +65 -65
  87. data/spec/docstring_spec.rb +137 -130
  88. data/spec/handlers/alias_handler_spec.rb +39 -39
  89. data/spec/handlers/attribute_handler_spec.rb +35 -35
  90. data/spec/handlers/base_spec.rb +60 -51
  91. data/spec/handlers/c/alias_handler_spec.rb +6 -6
  92. data/spec/handlers/c/attribute_handler_spec.rb +12 -12
  93. data/spec/handlers/c/class_handler_spec.rb +35 -22
  94. data/spec/handlers/c/constant_handler_spec.rb +24 -22
  95. data/spec/handlers/c/init_handler_spec.rb +10 -10
  96. data/spec/handlers/c/method_handler_spec.rb +150 -65
  97. data/spec/handlers/c/mixin_handler_spec.rb +5 -5
  98. data/spec/handlers/c/module_handler_spec.rb +27 -15
  99. data/spec/handlers/c/override_comment_handler_spec.rb +14 -14
  100. data/spec/handlers/c/path_handler_spec.rb +8 -8
  101. data/spec/handlers/c/spec_helper.rb +10 -0
  102. data/spec/handlers/c/struct_handler_spec.rb +3 -3
  103. data/spec/handlers/class_condition_handler_spec.rb +18 -18
  104. data/spec/handlers/class_handler_spec.rb +97 -97
  105. data/spec/handlers/class_method_handler_shared_examples.rb +132 -0
  106. data/spec/handlers/class_variable_handler_spec.rb +3 -3
  107. data/spec/handlers/constant_handler_spec.rb +32 -29
  108. data/spec/handlers/decorator_handler_methods_spec.rb +405 -0
  109. data/spec/handlers/dsl_handler_spec.rb +108 -109
  110. data/spec/handlers/examples/constant_handler_001.rb.txt +4 -1
  111. data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
  112. data/spec/handlers/exception_handler_spec.rb +23 -23
  113. data/spec/handlers/extend_handler_spec.rb +9 -9
  114. data/spec/handlers/legacy_base_spec.rb +60 -60
  115. data/spec/handlers/method_condition_handler_spec.rb +5 -5
  116. data/spec/handlers/method_handler_spec.rb +92 -92
  117. data/spec/handlers/mixin_handler_spec.rb +25 -25
  118. data/spec/handlers/module_function_handler_spec.rb +24 -24
  119. data/spec/handlers/module_handler_spec.rb +15 -15
  120. data/spec/handlers/private_class_method_handler_spec.rb +4 -48
  121. data/spec/handlers/private_constant_handler_spec.rb +8 -8
  122. data/spec/handlers/processor_spec.rb +12 -12
  123. data/spec/handlers/public_class_method_handler_spec.rb +10 -0
  124. data/spec/handlers/ruby/base_spec.rb +16 -16
  125. data/spec/handlers/ruby/legacy/base_spec.rb +20 -18
  126. data/spec/handlers/spec_helper.rb +1 -1
  127. data/spec/handlers/visibility_handler_spec.rb +25 -21
  128. data/spec/handlers/yield_handler_spec.rb +28 -28
  129. data/spec/i18n/locale_spec.rb +16 -16
  130. data/spec/i18n/message_spec.rb +8 -8
  131. data/spec/i18n/messages_spec.rb +14 -14
  132. data/spec/i18n/pot_generator_spec.rb +32 -32
  133. data/spec/i18n/text_spec.rb +22 -22
  134. data/spec/logging_spec.rb +12 -12
  135. data/spec/options_spec.rb +56 -56
  136. data/spec/parser/base_spec.rb +9 -9
  137. data/spec/parser/c_parser_spec.rb +50 -50
  138. data/spec/parser/ruby/ast_node_spec.rb +7 -7
  139. data/spec/parser/ruby/legacy/statement_list_spec.rb +106 -106
  140. data/spec/parser/ruby/legacy/token_list_spec.rb +27 -27
  141. data/spec/parser/ruby/ruby_parser_spec.rb +123 -113
  142. data/spec/parser/source_parser_spec.rb +224 -224
  143. data/spec/parser/tag_parsing_spec.rb +6 -7
  144. data/spec/rake/yardoc_task_spec.rb +38 -48
  145. data/spec/registry_spec.rb +143 -143
  146. data/spec/registry_store_spec.rb +165 -165
  147. data/spec/rubygems/doc_manager_spec.rb +38 -38
  148. data/spec/serializers/file_system_serializer_spec.rb +53 -33
  149. data/spec/serializers/yardoc_serializer_spec.rb +15 -15
  150. data/spec/server/adapter_spec.rb +15 -15
  151. data/spec/server/commands/base_spec.rb +29 -29
  152. data/spec/server/commands/library_command_spec.rb +12 -12
  153. data/spec/server/commands/static_file_command_spec.rb +28 -28
  154. data/spec/server/doc_server_helper_spec.rb +8 -8
  155. data/spec/server/doc_server_serializer_spec.rb +23 -18
  156. data/spec/server/rack_adapter_spec.rb +6 -6
  157. data/spec/server/router_spec.rb +39 -39
  158. data/spec/server/static_caching_spec.rb +16 -16
  159. data/spec/server/webrick_servlet_spec.rb +6 -7
  160. data/spec/server_spec.rb +3 -3
  161. data/spec/spec_helper.rb +11 -2
  162. data/spec/tags/default_factory_spec.rb +64 -64
  163. data/spec/tags/default_tag_spec.rb +5 -5
  164. data/spec/tags/directives_spec.rb +121 -121
  165. data/spec/tags/library_spec.rb +14 -14
  166. data/spec/tags/overload_tag_spec.rb +24 -24
  167. data/spec/tags/ref_tag_list_spec.rb +12 -12
  168. data/spec/templates/class_spec.rb +3 -3
  169. data/spec/templates/constant_spec.rb +4 -4
  170. data/spec/templates/engine_spec.rb +47 -48
  171. data/spec/templates/examples/class001.html +129 -101
  172. data/spec/templates/examples/class002.html +31 -27
  173. data/spec/templates/examples/method001.html +54 -47
  174. data/spec/templates/examples/method002.html +33 -28
  175. data/spec/templates/examples/method003.html +70 -64
  176. data/spec/templates/examples/method004.html +13 -9
  177. data/spec/templates/examples/method005.html +38 -32
  178. data/spec/templates/examples/module001.html +343 -339
  179. data/spec/templates/examples/module002.html +147 -124
  180. data/spec/templates/examples/module003.html +94 -81
  181. data/spec/templates/examples/module004.html +40 -33
  182. data/spec/templates/helpers/base_helper_spec.rb +91 -95
  183. data/spec/templates/helpers/html_helper_spec.rb +276 -279
  184. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +16 -15
  185. data/spec/templates/helpers/markup/rdoc_markup_spec.rb +27 -34
  186. data/spec/templates/helpers/markup_helper_spec.rb +57 -57
  187. data/spec/templates/helpers/method_helper_spec.rb +20 -20
  188. data/spec/templates/helpers/shared_signature_examples.rb +33 -31
  189. data/spec/templates/helpers/text_helper_spec.rb +6 -6
  190. data/spec/templates/method_spec.rb +7 -7
  191. data/spec/templates/module_spec.rb +7 -7
  192. data/spec/templates/onefile_spec.rb +7 -7
  193. data/spec/templates/section_spec.rb +66 -69
  194. data/spec/templates/spec_helper.rb +1 -1
  195. data/spec/templates/tag_spec.rb +5 -5
  196. data/spec/templates/template_spec.rb +158 -158
  197. data/spec/verifier_spec.rb +52 -52
  198. data/templates/default/fulldoc/html/css/full_list.css +32 -31
  199. data/templates/default/fulldoc/html/css/style.css +212 -77
  200. data/templates/default/fulldoc/html/frames.erb +6 -15
  201. data/templates/default/fulldoc/html/full_list.erb +14 -21
  202. data/templates/default/fulldoc/html/full_list_class.erb +1 -1
  203. data/templates/default/fulldoc/html/full_list_file.erb +6 -4
  204. data/templates/default/fulldoc/html/full_list_method.erb +8 -6
  205. data/templates/default/fulldoc/html/js/app.js +100 -76
  206. data/templates/default/fulldoc/html/js/full_list.js +170 -135
  207. data/templates/default/fulldoc/html/setup.rb +50 -7
  208. data/templates/default/layout/html/breadcrumb.erb +0 -2
  209. data/templates/default/layout/html/headers.erb +2 -1
  210. data/templates/default/layout/html/layout.erb +16 -10
  211. data/templates/default/layout/html/script_setup.erb +1 -2
  212. data/templates/default/layout/html/search.erb +7 -2
  213. data/templates/default/layout/html/setup.rb +16 -0
  214. data/templates/default/method/html/header.erb +7 -6
  215. data/templates/default/module/html/attribute_summary.erb +1 -1
  216. data/templates/default/module/html/box_info.erb +24 -18
  217. data/templates/default/module/html/constant_summary.erb +9 -11
  218. data/templates/default/module/html/item_summary.erb +1 -1
  219. data/templates/default/module/html/method_summary.erb +1 -1
  220. data/templates/guide/fulldoc/html/setup.rb +1 -1
  221. data/yard.gemspec +1 -2
  222. metadata +10 -7
  223. data/spec/handlers/examples/private_class_method_handler_001.rb.txt +0 -9
  224. data/spec/handlers/examples/private_class_method_handler_002.rb.txt +0 -18
  225. data/spec/handlers/examples/private_class_method_handler_003.rb.txt +0 -11
@@ -1,6 +1,6 @@
1
1
  # Handles the Init_Libname() method
2
2
  class YARD::Handlers::C::InitHandler < YARD::Handlers::C::Base
3
- MATCH = %r{\A\s*(?:static\s+)?void\s+(?:[Ii]nit_)?(\w+)\s*}
3
+ MATCH = %r{\A\s*(?:\S+\s+)*void\s+(?:[Ii]nit_)?(\w+)\s*}
4
4
  handles MATCH
5
5
  statement_class ToplevelStatement
6
6
 
@@ -6,9 +6,9 @@ class YARD::Handlers::C::MethodHandler < YARD::Handlers::C::Base
6
6
  module_function |
7
7
  private_method
8
8
  )
9
- \s*\(\s*([\w\.]+),
10
- \s*"([^"]+)",
11
- \s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\(|\(\w+\))?(\w+)\)?,
9
+ \s*\(\s*([\w\.]+)\s*,
10
+ \s*"([^"]+)"\s*,
11
+ \s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\(|\(\w+\))?(\w+)\)?\s*,
12
12
  \s*(-?\w+)\s*\)}xm
13
13
  MATCH2 = %r{rb_define_global_function\s*\(
14
14
  \s*"([^"]+)",
@@ -0,0 +1,132 @@
1
+ # Helper methods to assist with processing decorators.
2
+ module YARD::Handlers::Ruby::DecoratorHandlerMethods
3
+
4
+ # @overload process_decorator(*nodes, opts = {}, &block)
5
+ # Takes care of parsing method definitions passed to decorators
6
+ # as parameters, as well as parsing chained decorators.
7
+ #
8
+ # Use this in a handler's process block.
9
+ #
10
+ # @yieldparam method [YARD::CodeObjects::MethodObject] Method being decorated.
11
+ # @yieldparam node [YARD::Parser::Ruby::AstNode] AST node of the decorated method.
12
+ # @yieldparam name [Symbol] Name of the decorated method.
13
+ # @return [Array<Hash>] Array of hashes containing :method, :node, :name.
14
+ # See yield params.
15
+ #
16
+ # @param nodes [YARD::Parser::Ruby::AstNode] AST nodes that refer to decorated
17
+ # methods, like indexes of statement.parameter. Defaults to all parameters.
18
+ # Pass nil to specify zero parameters.
19
+ #
20
+ # @option opts [:instance, :class] :scope (:instance) Scope to use for each
21
+ # MethodObject.
22
+ #
23
+ # @option opts [true, false] :transfer_docstring Set false to disable
24
+ # transferring the decorator docstring to method definitions passed to the
25
+ # decorator as parameters.
26
+ #
27
+ # @option opts [true, false] :transfer_source Set false to disable
28
+ # transferring the decorator source code string to method definitions
29
+ # passed to the decorator as parameters.
30
+ #
31
+ # @example Basic Usage
32
+ # # Simply pass the method docs through to the method definition.
33
+ # process do
34
+ # process_decorator
35
+ # end
36
+ #
37
+ # @example Setting a method's visibility to private.
38
+ # process do
39
+ # process_decorator :scope => :class do |method|
40
+ # method.visibility = :private if method.respond_to? :visibility
41
+ # end
42
+ # end
43
+ def process_decorator(*nodes, &block)
44
+ opts = nodes.last.is_a?(Hash) ? nodes.pop : {}
45
+
46
+ all_nodes = statement.parameters.select do |p|
47
+ p.is_a? YARD::Parser::Ruby::AstNode
48
+ end
49
+
50
+ # Parse decorator parameters (decorator chain).
51
+ all_nodes.each do |param|
52
+ parse_block param if param.call? or param.def?
53
+ end
54
+
55
+ selected_nodes =
56
+ if nodes.empty?
57
+ all_nodes
58
+ elsif (nodes.count == 1 and nodes.first == nil)
59
+ []
60
+ else
61
+ nodes
62
+ end
63
+
64
+ decorated_methods = selected_nodes.map { |param|
65
+ process_decorator_parameter param, opts, &block
66
+ }.flatten
67
+
68
+ # Store method nodes in decorator node.
69
+ statement.define_singleton_method :decorators do
70
+ decorated_methods.map { |h| h[:node] }
71
+ end
72
+
73
+ decorated_methods
74
+ end
75
+
76
+ private
77
+
78
+ def process_decorator_parameter(node, opts={}, &block)
79
+ scope = opts.fetch :scope, :instance
80
+ transfer_docstring = opts.fetch :transfer_docstring, true
81
+ transfer_source = opts.fetch :transfer_source, true
82
+
83
+ name = nil
84
+
85
+ if node.call?
86
+ if node.respond_to? :decorators
87
+ return node.decorators.map do |n|
88
+ process_decorator_parameter n, opts, &block
89
+ end
90
+ end
91
+ elsif node.def?
92
+ name = node.jump(:def).method_name.source
93
+ else
94
+ name = node.jump(:ident, :string_content, :const).source
95
+ end
96
+
97
+ method = YARD::CodeObjects::Proxy.new(
98
+ namespace,
99
+ (scope == :instance ? '#' : '.') + name.to_s,
100
+ :method
101
+ )
102
+
103
+ # Transfer source to methods passed to the helper as parameters.
104
+ method.source = statement.source if transfer_source and node.def?
105
+
106
+ # Tag decorator on decorated method.
107
+ if method.respond_to? :add_tag
108
+ method.add_tag YARD::Tags::Tag.new(
109
+ :decorator,
110
+ statement.jump(:command).jump(:ident).source
111
+ )
112
+ end
113
+
114
+ # Transfer decorator docstring to methods passed to the helper as parameters.
115
+ if transfer_docstring \
116
+ and node.def? \
117
+ and statement.docstring \
118
+ and method.docstring.empty?
119
+ tags = method.tags if method.respond_to? :tags
120
+ tags ||= []
121
+
122
+ method.docstring = statement.docstring
123
+
124
+ tags.each { |t| method.add_tag t }
125
+ end
126
+
127
+ block.call method, node, name.to_sym if block_given?
128
+
129
+ [{:method => method, :node => node, :name => name.to_sym}]
130
+ end
131
+
132
+ end
@@ -15,7 +15,7 @@ class YARD::Handlers::Ruby::Legacy::PrivateClassMethodHandler < YARD::Handlers::
15
15
  method = Proxy.new(namespace, name)
16
16
  ensure_loaded!(method)
17
17
  method.visibility = :private
18
- rescue NamespaceMissingError
18
+ rescue YARD::Handlers::NamespaceMissingError
19
19
  raise UndocumentableError, "private visibility set on unrecognized method: #{name}"
20
20
  end
21
21
  end
@@ -1,46 +1,13 @@
1
- # Sets visibility of a class method
1
+ # Sets visibility of a class method to private.
2
2
  class YARD::Handlers::Ruby::PrivateClassMethodHandler < YARD::Handlers::Ruby::Base
3
+ include YARD::Handlers::Ruby::DecoratorHandlerMethods
4
+
3
5
  handles method_call(:private_class_method)
4
6
  namespace_only
5
7
 
6
8
  process do
7
- errors = []
8
- statement.parameters.each do |param|
9
- next unless AstNode === param
10
- begin
11
- privatize_class_method(param)
12
- rescue UndocumentableError => err
13
- errors << err.message
14
- end
15
- end
16
- if errors.size > 0
17
- msg = errors.size == 1 ? ": #{errors[0]}" : "s: #{errors.join(", ")}"
18
- raise UndocumentableError, "private class_method#{msg} for #{namespace.path}"
19
- end
20
- end
21
-
22
- private
23
-
24
- def privatize_class_method(node)
25
- if node.literal?
26
- method = Proxy.new(namespace, node[0][0][0], :method)
27
-
28
- # Proxy will not have a #visibility method when handling inherited class methods
29
- # like :new, yet "private_class_method :new" is valid Ruby syntax. Therefore
30
- # if Proxy doesn't respond to #visibility, the object should be skipped.
31
- #
32
- # However, it is important to note that classes can be reopened, and
33
- # private_class_method can be called inside these reopened classes.
34
- # Therefore when encountering private_class_method, all of the files need
35
- # to be parsed before checking if Proxy responds to #visibility. If this
36
- # is not done, it is possible that class methods may be incorrectly marked
37
- # public/private.
38
- parser.parse_remaining_files
39
- method.visibility = :private if method.respond_to? :visibility
40
- else
41
- raise UndocumentableError, "invalid argument to private_class_method: #{node.source}"
9
+ process_decorator :scope => :class do |method|
10
+ method.visibility = :private if method.respond_to? :visibility=
42
11
  end
43
- rescue NamespaceMissingError
44
- raise UndocumentableError, "private visibility set on unrecognized method: #{node[0]}"
45
12
  end
46
- end
13
+ end
@@ -1,36 +1,42 @@
1
1
  # Sets visibility of a constant (class, module, const)
2
- class YARD::Handlers::Ruby::PrivateConstantHandler < YARD::Handlers::Ruby::Base
3
- handles method_call(:private_constant)
4
- namespace_only
2
+ module YARD
3
+ module Handlers
4
+ module Ruby
5
+ class PrivateConstantHandler < YARD::Handlers::Ruby::Base
6
+ handles method_call(:private_constant)
7
+ namespace_only
5
8
 
6
- process do
7
- errors = []
8
- statement.parameters.each do |param|
9
- next unless AstNode === param
10
- begin
11
- privatize_constant(param)
12
- rescue UndocumentableError => err
13
- errors << err.message
14
- end
15
- end
16
- if errors.size > 0
17
- msg = errors.size == 1 ? ": #{errors[0]}" : "s: #{errors.join(", ")}"
18
- raise UndocumentableError, "private constant#{msg} for #{namespace.path}"
19
- end
20
- end
9
+ process do
10
+ errors = []
11
+ statement.parameters.each do |param|
12
+ next unless AstNode === param
13
+ begin
14
+ privatize_constant(param)
15
+ rescue UndocumentableError => err
16
+ errors << err.message
17
+ end
18
+ end
19
+ if errors.size > 0
20
+ msg = errors.size == 1 ? ": #{errors[0]}" : "s: #{errors.join(", ")}"
21
+ raise UndocumentableError, "private constant#{msg} for #{namespace.path}"
22
+ end
23
+ end
21
24
 
22
- private
25
+ private
23
26
 
24
- def privatize_constant(node)
25
- if node.literal? || (node.type == :var_ref && node[0].type == :const)
26
- node = node.jump(:tstring_content, :const)
27
- const = Proxy.new(namespace, node[0])
28
- ensure_loaded!(const)
29
- const.visibility = :private
30
- else
31
- raise UndocumentableError, "invalid argument to private_constant: #{node.source}"
27
+ def privatize_constant(node)
28
+ if node.literal? || (node.type == :var_ref && node[0].type == :const)
29
+ node = node.jump(:tstring_content, :const)
30
+ const = Proxy.new(namespace, node[0])
31
+ ensure_loaded!(const)
32
+ const.visibility = :private
33
+ else
34
+ raise UndocumentableError, "invalid argument to private_constant: #{node.source}"
35
+ end
36
+ rescue NamespaceMissingError
37
+ raise UndocumentableError, "private visibility set on unrecognized constant: #{node[0]}"
38
+ end
39
+ end
32
40
  end
33
- rescue NamespaceMissingError
34
- raise UndocumentableError, "private visibility set on unrecognized constant: #{node[0]}"
35
41
  end
36
- end
42
+ end
@@ -0,0 +1,13 @@
1
+ # Sets visibility of a class method to public.
2
+ class YARD::Handlers::Ruby::PublicClassMethodHandler < YARD::Handlers::Ruby::Base
3
+ include YARD::Handlers::Ruby::DecoratorHandlerMethods
4
+
5
+ handles method_call(:public_class_method)
6
+ namespace_only
7
+
8
+ process do
9
+ process_decorator :scope => :class do |method|
10
+ method.visibility = :public if method.respond_to? :visibility
11
+ end
12
+ end
13
+ end
@@ -133,6 +133,7 @@ module YARD::Handlers::Ruby::StructHandlerMethods
133
133
  def create_attributes(klass, members)
134
134
  # For each parameter, add reader and writers
135
135
  members.each do |member|
136
+ next if klass.attributes[:instance][member]
136
137
  klass.attributes[:instance][member] = SymbolHash[:read => nil, :write => nil]
137
138
  create_writer klass, member if create_member_method?(klass, member, :write)
138
139
  create_reader klass, member if create_member_method?(klass, member, :read)
@@ -1,5 +1,7 @@
1
1
  # Handles 'private', 'protected', and 'public' calls.
2
2
  class YARD::Handlers::Ruby::VisibilityHandler < YARD::Handlers::Ruby::Base
3
+ include YARD::Handlers::Ruby::DecoratorHandlerMethods
4
+
3
5
  handles method_call(:private)
4
6
  handles method_call(:protected)
5
7
  handles method_call(:public)
@@ -11,14 +13,9 @@ class YARD::Handlers::Ruby::VisibilityHandler < YARD::Handlers::Ruby::Base
11
13
  when :var_ref, :vcall
12
14
  self.visibility = ident.first.to_sym
13
15
  when :fcall, :command
14
- statement[1].traverse do |node|
15
- case node.type
16
- when :symbol; source = node.first.source
17
- when :string_content; source = node.source
18
- else next
19
- end
20
- MethodObject.new(namespace, source, scope) {|o| o.visibility = ident.first }
16
+ process_decorator do |method|
17
+ method.visibility = ident.first if method.respond_to? :visibility=
21
18
  end
22
19
  end
23
20
  end
24
- end
21
+ end
@@ -164,6 +164,7 @@ module YARD
164
164
  def enter_level(new_level = level, &block)
165
165
  old_level, self.level = level, new_level
166
166
  yield
167
+ ensure
167
168
  self.level = old_level
168
169
  end
169
170
 
@@ -219,7 +219,7 @@ module YARD
219
219
  node.line_range = Range.new(lstart, lineno)
220
220
  if node.respond_to?(:block)
221
221
  sr, lr = node.block.source_range, node.block.line_range
222
- node.block.source_range = Range.new(sr.first, @tokens.last[2][1])
222
+ node.block.source_range = Range.new(sr.first, @tokens.last[2][1]-1)
223
223
  node.block.line_range = Range.new(lr.first, @tokens.last[2][0])
224
224
  end
225
225
  node
@@ -634,4 +634,4 @@ module YARD
634
634
  end if defined?(::Ripper)
635
635
  end
636
636
  end
637
- end
637
+ end
@@ -63,6 +63,10 @@ module YARD
63
63
  SHEBANG_LINE = /\A\s*#!\S+/
64
64
  ENCODING_LINE = /\A(?:\s*#*!.*\r?\n)?\s*(?:#+|\/\*+|\/\/+).*coding\s*[:=]{1,2}\s*([a-z\d_\-]+)/i
65
65
 
66
+ # The default glob of files to be parsed.
67
+ # @since 0.9.0
68
+ DEFAULT_PATH_GLOB = ["{lib,app}/**/*.rb", "ext/**/*.{c,cc,cxx,cpp}"]
69
+
66
70
  # Byte order marks for various encodings
67
71
  # @since 0.7.0
68
72
  ENCODING_BYTE_ORDER_MARKS = {
@@ -90,7 +94,7 @@ module YARD
90
94
  # @param [Fixnum] level the logger level to use during parsing. See
91
95
  # {YARD::Logger}
92
96
  # @return [void]
93
- def parse(paths = ["{lib,app}/**/*.rb", "ext/**/*.c"], excluded = [], level = log.level)
97
+ def parse(paths = DEFAULT_PATH_GLOB, excluded = [], level = log.level)
94
98
  log.debug("Parsing #{paths.inspect} with `#{parser_type}` parser")
95
99
  excluded = excluded.map do |path|
96
100
  case path
@@ -99,7 +103,7 @@ module YARD
99
103
  end
100
104
  end
101
105
  files = [paths].flatten.
102
- map {|p| File.directory?(p) ? "#{p}/**/*.{rb,c}" : p }.
106
+ map {|p| File.directory?(p) ? "#{p}/**/*.{rb,c,cc,cxx,cpp}" : p }.
103
107
  map {|p| p.include?("*") ? Dir[p].sort_by {|f| f.length } : p }.flatten.
104
108
  reject {|p| !File.file?(p) || excluded.any? {|re| p =~ re } }
105
109
 
@@ -147,16 +151,12 @@ module YARD
147
151
  # @return [Hash{Symbol=>Object}] a list of registered parser types
148
152
  # @private
149
153
  # @since 0.5.6
150
- attr_reader :parser_types
151
- undef parser_types
152
154
  def parser_types; @@parser_types ||= {} end
153
155
  def parser_types=(value) @@parser_types = value end
154
156
 
155
157
  # @return [Hash] a list of registered parser type extensions
156
158
  # @private
157
159
  # @since 0.5.6
158
- attr_reader :parser_type_extensions
159
- undef parser_type_extensions
160
160
  def parser_type_extensions; @@parser_type_extensions ||= {} end
161
161
  def parser_type_extensions=(value) @@parser_type_extensions = value end
162
162
 
@@ -66,12 +66,12 @@ module YARD
66
66
  # Defines the rake task
67
67
  # @return [void]
68
68
  def define
69
- desc "Generate YARD Documentation" unless ::Rake.application.last_comment
69
+ desc "Generate YARD Documentation" unless ::Rake.application.last_description
70
70
  task(name) do
71
71
  before.call if before.is_a?(Proc)
72
72
  yardoc = YARD::CLI::Yardoc.new
73
73
  yardoc.options[:verifier] = verifier if verifier
74
- yardoc.run *(options + files)
74
+ yardoc.run(*(options + files))
75
75
  YARD::CLI::Stats.run(*(stats_options + ['--use-cache'])) unless stats_options.empty?
76
76
  after.call if after.is_a?(Proc)
77
77
  end
@@ -26,6 +26,7 @@ module YARD
26
26
  # path filename. If this is set to the empty string, no extension is used.
27
27
  def initialize(opts = {})
28
28
  super
29
+ @name_map = nil
29
30
  @basepath = (options[:basepath] || 'doc').to_s
30
31
  @extension = (options.has_key?(:extension) ? options[:extension] : 'html').to_s
31
32
  end
@@ -51,7 +52,7 @@ module YARD
51
52
  if object.is_a?(CodeObjects::ExtraFileObject)
52
53
  fspath = ['file.' + object.name + (extension.empty? ? '' : ".#{extension}")]
53
54
  else
54
- objname = object != YARD::Registry.root ? object.name.to_s : "top-level-namespace"
55
+ objname = object != YARD::Registry.root ? mapped_name(object) : "top-level-namespace"
55
56
  objname += '_' + object.scope.to_s[0,1] if object.is_a?(CodeObjects::MethodObject)
56
57
  fspath = [objname + (extension.empty? ? '' : ".#{extension}")]
57
58
  if object.namespace && object.namespace.path != ""
@@ -72,6 +73,37 @@ module YARD
72
73
 
73
74
  private
74
75
 
76
+ # Builds a filename mapping from object paths to filesystem path names.
77
+ # Needed to handle case sensitive YARD objects mapped into a case
78
+ # insensitive filesystem. Uses with {#mapped_name} to determine the
79
+ # mapping name for a given object.
80
+ #
81
+ # @note In order to use filesystem name mapping, you must initialize
82
+ # the serializer object after preparing the {YARD::Registry}.
83
+ def build_filename_map
84
+ @name_map = {}
85
+ YARD::Registry.all.each do |object|
86
+ lpath = nil
87
+ if object.parent && object.parent.type != :root
88
+ lpath = object.parent.path + "::" + object.name.to_s.downcase
89
+ else
90
+ lpath = object.path.downcase
91
+ end
92
+
93
+ @name_map[lpath] ||= {}
94
+ size = @name_map[lpath].size
95
+ name = "#{object.name}#{size > 0 ? "_" * size : ""}"
96
+ @name_map[lpath][object.name] = name
97
+ end
98
+ end
99
+
100
+ # @return [String] the filesystem mapped name of a given object.
101
+ def mapped_name(object)
102
+ build_filename_map if !@name_map
103
+ map = @name_map[object.path.downcase]
104
+ return map && map[object.name] ? map[object.name] : object.name.to_s
105
+ end
106
+
75
107
  # Remove special chars from filenames.
76
108
  # Windows disallows \ / : * ? " < > | but we will just remove any
77
109
  # non alphanumeric (plus period, underscore and dash).