yard 0.2.3.5 → 0.4.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.
- data/.yardopts +12 -10
- data/ChangeLog +5686 -0
- data/{README.markdown → README.md} +65 -11
- data/Rakefile +25 -13
- data/benchmarks/concat_vs_join.rb +12 -0
- data/benchmarks/erb_vs_erubis.rb +14 -14
- data/benchmarks/marshal_vs_dbm.rb +1 -1
- data/benchmarks/pathname_vs_string.rb +50 -0
- data/benchmarks/template_erb.rb +22 -0
- data/benchmarks/template_format.rb +6 -0
- data/benchmarks/template_profile.rb +17 -0
- data/bin/yri +16 -7
- data/docs/{CODE_OBJECTS.markdown → CodeObjects.md} +0 -0
- data/docs/{GETTING_STARTED.markdown → GettingStarted.md} +49 -11
- data/docs/{GLOSSARY.markdown → Glossary.md} +0 -0
- data/docs/{HANDLERS.markdown → Handlers.md} +5 -5
- data/docs/{OVERVIEW.markdown → Overview.md} +9 -13
- data/docs/{PARSER.markdown → Parser.md} +1 -1
- data/docs/{TAGS.markdown → Tags.md} +1 -1
- data/docs/Templates.md +286 -0
- data/docs/{WHATSNEW.markdown → WhatsNew.md} +82 -2
- data/lib/rubygems_plugin.rb +17 -20
- data/lib/yard.rb +47 -1
- data/lib/yard/autoload.rb +38 -47
- data/lib/yard/cli/yard_graph.rb +36 -13
- data/lib/yard/cli/yardoc.rb +74 -12
- data/lib/yard/code_objects/base.rb +182 -14
- data/lib/yard/code_objects/class_object.rb +39 -2
- data/lib/yard/code_objects/class_variable_object.rb +4 -0
- data/lib/yard/code_objects/constant_object.rb +8 -0
- data/lib/yard/code_objects/extended_method_object.rb +14 -0
- data/lib/yard/code_objects/method_object.rb +60 -2
- data/lib/yard/code_objects/module_object.rb +6 -0
- data/lib/yard/code_objects/namespace_object.rb +99 -2
- data/lib/yard/code_objects/proxy.rb +53 -6
- data/lib/yard/code_objects/root_object.rb +2 -0
- data/lib/yard/core_ext/array.rb +61 -0
- data/lib/yard/core_ext/file.rb +21 -4
- data/lib/yard/core_ext/module.rb +11 -1
- data/lib/yard/core_ext/string.rb +13 -2
- data/lib/yard/core_ext/symbol_hash.rb +51 -3
- data/lib/yard/docstring.rb +68 -19
- data/lib/yard/globals.rb +5 -2
- data/lib/yard/handlers/base.rb +13 -3
- data/lib/yard/handlers/processor.rb +64 -2
- data/lib/yard/handlers/ruby/class_handler.rb +1 -1
- data/lib/yard/handlers/ruby/class_variable_handler.rb +5 -1
- data/lib/yard/handlers/ruby/constant_handler.rb +38 -4
- data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/base.rb +2 -2
- data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +6 -3
- data/lib/yard/handlers/ruby/legacy/constant_handler.rb +21 -2
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +10 -0
- data/lib/yard/handlers/ruby/legacy/yield_handler.rb +2 -1
- data/lib/yard/handlers/ruby/method_handler.rb +10 -0
- data/lib/yard/handlers/ruby/yield_handler.rb +2 -1
- data/lib/yard/logging.rb +17 -0
- data/lib/yard/parser/ruby/ast_node.rb +101 -0
- data/lib/yard/parser/ruby/legacy/ruby_lex.rb +2 -2
- data/lib/yard/parser/ruby/legacy/statement_list.rb +10 -9
- data/lib/yard/parser/ruby/ruby_parser.rb +32 -3
- data/lib/yard/parser/source_parser.rb +82 -5
- data/lib/yard/rake/yardoc_task.rb +38 -3
- data/lib/yard/registry.rb +112 -2
- data/lib/yard/serializers/base.rb +48 -1
- data/lib/yard/serializers/file_system_serializer.rb +23 -2
- data/lib/yard/serializers/process_serializer.rb +10 -0
- data/lib/yard/serializers/stdout_serializer.rb +11 -0
- data/lib/yard/tags/library.rb +4 -1
- data/lib/yard/tags/overload_tag.rb +3 -12
- data/lib/yard/templates/engine.rb +162 -0
- data/lib/yard/{generators → templates}/helpers/base_helper.rb +14 -13
- data/lib/yard/{generators → templates}/helpers/filter_helper.rb +1 -1
- data/lib/yard/templates/helpers/html_helper.rb +287 -0
- data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +29 -0
- data/lib/yard/templates/helpers/html_syntax_highlight_helper18.rb +27 -0
- data/lib/yard/{generators → templates}/helpers/markup_helper.rb +15 -11
- data/lib/yard/{generators → templates}/helpers/method_helper.rb +8 -1
- data/lib/yard/templates/helpers/module_helper.rb +15 -0
- data/lib/yard/templates/helpers/text_helper.rb +60 -0
- data/lib/yard/templates/helpers/uml_helper.rb +33 -0
- data/lib/yard/templates/template.rb +355 -0
- data/lib/yard/verifier.rb +110 -0
- data/spec/cli/yardoc_spec.rb +23 -1
- data/spec/code_objects/base_spec.rb +8 -0
- data/spec/code_objects/class_object_spec.rb +166 -156
- data/spec/code_objects/method_object_spec.rb +2 -2
- data/spec/code_objects/module_object_spec.rb +112 -110
- data/spec/code_objects/proxy_spec.rb +9 -0
- data/spec/core_ext/array_spec.rb +33 -0
- data/spec/core_ext/file_spec.rb +40 -12
- data/spec/core_ext/module_spec.rb +15 -0
- data/spec/core_ext/string_spec.rb +10 -2
- data/spec/docstring_spec.rb +157 -135
- data/spec/handlers/class_handler_spec.rb +3 -0
- data/spec/handlers/class_variable_handler_spec.rb +3 -1
- data/spec/handlers/constant_handler_spec.rb +38 -0
- data/spec/handlers/examples/class_handler_001.rb.txt +14 -1
- data/spec/handlers/examples/class_variable_handler_001.rb.txt +1 -0
- data/spec/handlers/examples/constant_handler_001.rb.txt +10 -1
- data/spec/handlers/examples/exception_handler_001.rb.txt +5 -0
- data/spec/handlers/examples/method_handler_001.rb.txt +15 -0
- data/spec/handlers/examples/mixin_handler_001.rb.txt +13 -0
- data/spec/handlers/exception_handler_spec.rb +4 -0
- data/spec/handlers/method_handler_spec.rb +22 -0
- data/spec/handlers/mixin_handler_spec.rb +5 -3
- data/spec/handlers/yield_handler_spec.rb +1 -1
- data/spec/parser/ruby/ast_node_spec.rb +16 -0
- data/spec/parser/ruby/legacy/statement_list_spec.rb +36 -0
- data/spec/parser/ruby/ruby_parser_spec.rb +80 -0
- data/spec/parser/source_parser_spec.rb +48 -2
- data/spec/rake/yardoc_task_spec.rb +62 -25
- data/spec/serializers/file_system_serializer_spec.rb +1 -1
- data/spec/templates/class_spec.rb +34 -0
- data/spec/templates/engine_spec.rb +121 -0
- data/spec/templates/examples/class001.html +271 -0
- data/spec/templates/examples/class001.txt +31 -0
- data/spec/templates/examples/method001.html +96 -0
- data/spec/templates/examples/method001.txt +28 -0
- data/spec/templates/examples/method002.html +81 -0
- data/spec/templates/examples/method002.txt +20 -0
- data/spec/templates/examples/method003.html +137 -0
- data/spec/templates/examples/method003.txt +45 -0
- data/spec/templates/examples/module001.dot +31 -0
- data/spec/templates/examples/module001.html +294 -0
- data/spec/templates/examples/module001.txt +33 -0
- data/spec/templates/examples/tag001.txt +82 -0
- data/spec/templates/helpers/base_helper_spec.rb +129 -0
- data/spec/{generators → templates}/helpers/html_helper_spec.rb +73 -16
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +39 -0
- data/spec/{generators → templates}/helpers/markup_helper_spec.rb +6 -7
- data/spec/templates/method_spec.rb +75 -0
- data/spec/templates/module_spec.rb +50 -0
- data/spec/templates/spec_helper.rb +33 -0
- data/spec/templates/tag_spec.rb +39 -0
- data/spec/templates/template_spec.rb +398 -0
- data/spec/verifier_spec.rb +51 -0
- data/spec/yard_spec.rb +46 -0
- data/templates/default/class/dot/setup.rb +6 -0
- data/templates/default/class/dot/superklass.erb +3 -0
- data/templates/default/class/html/constructor_details.erb +8 -0
- data/templates/default/class/html/setup.rb +1 -0
- data/templates/default/class/html/subclasses.erb +4 -0
- data/templates/default/class/setup.rb +29 -0
- data/templates/default/class/text/setup.rb +11 -0
- data/templates/default/class/text/subclasses.erb +5 -0
- data/templates/default/docstring/html/abstract.erb +4 -0
- data/templates/default/docstring/html/deprecated.erb +1 -0
- data/templates/default/docstring/html/index.erb +5 -0
- data/templates/default/docstring/html/note.erb +6 -0
- data/templates/default/docstring/html/text.erb +1 -0
- data/templates/default/docstring/html/todo.erb +6 -0
- data/templates/default/docstring/setup.rb +39 -0
- data/templates/default/docstring/text/abstract.erb +2 -0
- data/templates/default/docstring/text/deprecated.erb +2 -0
- data/templates/default/docstring/text/index.erb +2 -0
- data/templates/default/docstring/text/note.erb +4 -0
- data/templates/default/docstring/text/text.erb +1 -0
- data/templates/default/docstring/text/todo.erb +4 -0
- data/templates/default/fulldoc/html/css/common.css +1 -0
- data/templates/default/fulldoc/html/css/full_list.css +23 -0
- data/templates/default/fulldoc/html/css/style.css +261 -0
- data/templates/default/fulldoc/html/full_list.erb +36 -0
- data/templates/default/fulldoc/html/js/app.js +91 -0
- data/templates/default/fulldoc/html/js/full_list.js +39 -0
- data/templates/default/fulldoc/html/js/jquery.js +19 -0
- data/templates/default/fulldoc/html/setup.rb +86 -0
- data/templates/default/{uml → layout}/dot/header.erb +2 -2
- data/templates/default/layout/dot/setup.rb +14 -0
- data/templates/default/layout/html/breadcrumb.erb +11 -0
- data/templates/default/layout/html/footer.erb +5 -0
- data/templates/default/layout/html/headers.erb +13 -0
- data/templates/default/layout/html/index.erb +49 -0
- data/templates/default/layout/html/layout.erb +20 -0
- data/templates/default/layout/html/search.erb +5 -0
- data/templates/default/layout/html/setup.rb +58 -0
- data/templates/default/method/html/header.erb +14 -3
- data/templates/default/method/setup.rb +3 -0
- data/templates/default/method/text/header.erb +1 -1
- data/templates/default/method_details/html/header.erb +3 -0
- data/templates/default/method_details/html/method_signature.erb +17 -0
- data/templates/default/method_details/html/source.erb +10 -0
- data/templates/default/method_details/setup.rb +8 -0
- data/templates/default/method_details/text/header.erb +10 -0
- data/templates/default/method_details/text/method_signature.erb +12 -0
- data/templates/default/method_details/text/setup.rb +10 -0
- data/templates/default/module/dot/child.erb +1 -0
- data/templates/default/module/dot/dependencies.erb +3 -0
- data/templates/default/{uml/dot/subgraph.erb → module/dot/header.erb} +3 -3
- data/templates/default/{uml → module}/dot/info.erb +4 -4
- data/templates/default/module/dot/setup.rb +14 -0
- data/templates/default/module/html/attribute_details.erb +11 -0
- data/templates/default/module/html/attribute_summary.erb +8 -0
- data/templates/default/module/html/box_info.erb +32 -0
- data/templates/default/module/html/children.erb +8 -0
- data/templates/default/module/html/constant_summary.erb +13 -0
- data/templates/default/module/html/defines.erb +3 -0
- data/templates/default/module/html/header.erb +4 -4
- data/templates/default/module/html/inherited_constants.erb +8 -0
- data/templates/default/module/html/inherited_methods.erb +9 -0
- data/templates/default/module/html/item_summary.erb +20 -0
- data/templates/default/module/html/method_details_list.erb +8 -0
- data/templates/default/module/html/method_summary.erb +8 -0
- data/templates/default/module/html/methodmissing.erb +12 -0
- data/templates/default/module/html/pre_docstring.erb +1 -0
- data/templates/default/module/setup.rb +83 -0
- data/templates/default/module/text/children.erb +10 -0
- data/templates/default/module/text/class_meths_list.erb +8 -0
- data/templates/default/module/text/extends.erb +8 -0
- data/templates/default/module/text/header.erb +7 -0
- data/templates/default/module/text/includes.erb +8 -0
- data/templates/default/module/text/instance_meths_list.erb +8 -0
- data/templates/default/module/text/setup.rb +12 -0
- data/templates/default/root/dot/child.erb +3 -0
- data/templates/default/root/dot/setup.rb +5 -0
- data/templates/default/tags/html/example.erb +5 -16
- data/templates/default/tags/html/index.erb +3 -0
- data/templates/default/tags/html/option.erb +17 -20
- data/templates/default/tags/html/overload.erb +13 -0
- data/templates/default/tags/html/see.erb +5 -10
- data/templates/default/tags/html/tag.erb +20 -0
- data/templates/default/tags/setup.rb +50 -0
- data/templates/default/tags/text/example.erb +8 -10
- data/templates/default/tags/text/index.erb +1 -0
- data/templates/default/tags/text/option.erb +18 -3
- data/templates/default/tags/text/overload.erb +19 -0
- data/templates/default/tags/text/see.erb +8 -2
- data/templates/default/tags/text/tag.erb +13 -0
- metadata +142 -158
- data/bin/view_generator +0 -17
- data/docs/FAQ.markdown +0 -34
- data/docs/GENERATORS.markdown +0 -211
- data/lib/yard/generators/attributes_generator.rb +0 -22
- data/lib/yard/generators/base.rb +0 -305
- data/lib/yard/generators/class_generator.rb +0 -27
- data/lib/yard/generators/constants_generator.rb +0 -74
- data/lib/yard/generators/constructor_generator.rb +0 -25
- data/lib/yard/generators/deprecated_generator.rb +0 -15
- data/lib/yard/generators/docstring_generator.rb +0 -15
- data/lib/yard/generators/full_doc_generator.rb +0 -127
- data/lib/yard/generators/helpers/html_helper.rb +0 -196
- data/lib/yard/generators/helpers/html_syntax_highlight_helper.rb +0 -49
- data/lib/yard/generators/helpers/uml_helper.rb +0 -16
- data/lib/yard/generators/inheritance_generator.rb +0 -16
- data/lib/yard/generators/method_details_generator.rb +0 -18
- data/lib/yard/generators/method_generator.rb +0 -43
- data/lib/yard/generators/method_listing_generator.rb +0 -105
- data/lib/yard/generators/method_missing_generator.rb +0 -25
- data/lib/yard/generators/method_signature_generator.rb +0 -19
- data/lib/yard/generators/method_summary_generator.rb +0 -21
- data/lib/yard/generators/mixins_generator.rb +0 -21
- data/lib/yard/generators/module_generator.rb +0 -23
- data/lib/yard/generators/overloads_generator.rb +0 -20
- data/lib/yard/generators/quick_doc_generator.rb +0 -25
- data/lib/yard/generators/root_generator.rb +0 -32
- data/lib/yard/generators/source_generator.rb +0 -11
- data/lib/yard/generators/tags_generator.rb +0 -99
- data/lib/yard/generators/uml_generator.rb +0 -102
- data/lib/yard/generators/visibility_group_generator.rb +0 -26
- data/spec/generators/base_spec.rb +0 -64
- data/spec/generators/full_doc_generator_spec.rb +0 -29
- data/spec/generators/helpers/base_helper_spec.rb +0 -15
- data/spec/generators/quick_doc_generator_spec.rb +0 -13
- data/templates/default/attributes/html/header.erb +0 -47
- data/templates/default/attributes/text/header.erb +0 -10
- data/templates/default/class/html/header.erb +0 -4
- data/templates/default/constants/html/constants.erb +0 -9
- data/templates/default/constants/html/header.erb +0 -3
- data/templates/default/constants/html/included.erb +0 -9
- data/templates/default/constants/html/inherited.erb +0 -9
- data/templates/default/constructor/html/header.erb +0 -10
- data/templates/default/deprecated/html/main.erb +0 -6
- data/templates/default/deprecated/text/main.erb +0 -3
- data/templates/default/docstring/html/main.erb +0 -3
- data/templates/default/docstring/text/main.erb +0 -3
- data/templates/default/fulldoc/html/all_files.erb +0 -19
- data/templates/default/fulldoc/html/all_methods.erb +0 -26
- data/templates/default/fulldoc/html/all_namespaces.erb +0 -22
- data/templates/default/fulldoc/html/app.js +0 -18
- data/templates/default/fulldoc/html/custom.css +0 -1
- data/templates/default/fulldoc/html/file.erb +0 -16
- data/templates/default/fulldoc/html/footer.erb +0 -5
- data/templates/default/fulldoc/html/header.erb +0 -16
- data/templates/default/fulldoc/html/html_head.erb +0 -4
- data/templates/default/fulldoc/html/index.erb +0 -19
- data/templates/default/fulldoc/html/jquery.js +0 -11
- data/templates/default/fulldoc/html/style.css +0 -81
- data/templates/default/fulldoc/html/syntax_highlight.css +0 -24
- data/templates/default/inheritance/html/header.erb +0 -8
- data/templates/default/inheritance/text/header.erb +0 -3
- data/templates/default/method/html/aliases.erb +0 -6
- data/templates/default/method/html/title.erb +0 -3
- data/templates/default/method/text/title.erb +0 -1
- data/templates/default/methoddetails/html/header.erb +0 -8
- data/templates/default/methoddetails/html/method_header.erb +0 -3
- data/templates/default/methodmissing/html/header.erb +0 -12
- data/templates/default/methodsignature/html/main.erb +0 -10
- data/templates/default/methodsignature/text/main.erb +0 -8
- data/templates/default/methodsummary/html/header.erb +0 -5
- data/templates/default/methodsummary/html/included.erb +0 -9
- data/templates/default/methodsummary/html/inherited.erb +0 -9
- data/templates/default/methodsummary/html/summary.erb +0 -29
- data/templates/default/methodsummary/text/header.erb +0 -5
- data/templates/default/methodsummary/text/included.erb +0 -0
- data/templates/default/methodsummary/text/inherited.erb +0 -0
- data/templates/default/methodsummary/text/summary.erb +0 -6
- data/templates/default/mixins/html/header.erb +0 -4
- data/templates/default/overloads/html/header.erb +0 -8
- data/templates/default/overloads/text/header.erb +0 -8
- data/templates/default/quickdoc/html/header.erb +0 -15
- data/templates/default/quickdoc/text/header.erb +0 -12
- data/templates/default/root/html/header.erb +0 -4
- data/templates/default/source/html/main.erb +0 -15
- data/templates/default/source/text/main.erb +0 -4
- data/templates/default/tags/html/header.erb +0 -4
- data/templates/default/tags/html/param.erb +0 -21
- data/templates/default/tags/html/tags.erb +0 -23
- data/templates/default/tags/html/todo.erb +0 -8
- data/templates/default/tags/text/header.erb +0 -3
- data/templates/default/tags/text/param.erb +0 -9
- data/templates/default/tags/text/tags.erb +0 -7
- data/templates/default/uml/dot/child.erb +0 -1
- data/templates/default/uml/dot/dependencies.erb +0 -10
- data/templates/default/uml/dot/superclasses.erb +0 -9
- data/templates/default/uml/dot/unknown.erb +0 -3
- data/templates/default/uml/dot/unknown_child.erb +0 -1
- data/templates/default/visibilitygroup/html/header.erb +0 -6
- data/templates/javadoc/attributes/html/header.erb +0 -16
- data/templates/javadoc/class/html/header.erb +0 -4
- data/templates/javadoc/constants/html/constants.erb +0 -9
- data/templates/javadoc/constants/html/header.erb +0 -3
- data/templates/javadoc/constants/html/included.erb +0 -12
- data/templates/javadoc/constants/html/inherited.erb +0 -12
- data/templates/javadoc/constructor/html/header.erb +0 -10
- data/templates/javadoc/deprecated/html/main.erb +0 -0
- data/templates/javadoc/docstring/html/main.erb +0 -6
- data/templates/javadoc/fulldoc/html/all_methods.erb +0 -25
- data/templates/javadoc/fulldoc/html/all_namespaces.erb +0 -19
- data/templates/javadoc/fulldoc/html/app.js +0 -18
- data/templates/javadoc/fulldoc/html/header.erb +0 -15
- data/templates/javadoc/fulldoc/html/html_head.erb +0 -3
- data/templates/javadoc/fulldoc/html/index.erb +0 -18
- data/templates/javadoc/fulldoc/html/jquery.js +0 -11
- data/templates/javadoc/fulldoc/html/readme.erb +0 -15
- data/templates/javadoc/fulldoc/html/style.css +0 -22
- data/templates/javadoc/fulldoc/html/syntax_highlight.css +0 -21
- data/templates/javadoc/inheritance/html/header.erb +0 -6
- data/templates/javadoc/method/html/aliases.erb +0 -6
- data/templates/javadoc/method/html/header.erb +0 -4
- data/templates/javadoc/method/html/title.erb +0 -4
- data/templates/javadoc/methoddetails/html/header.erb +0 -8
- data/templates/javadoc/methoddetails/html/method_header.erb +0 -0
- data/templates/javadoc/methodmissing/html/header.erb +0 -12
- data/templates/javadoc/methodsignature/html/main.erb +0 -8
- data/templates/javadoc/methodsummary/html/header.erb +0 -5
- data/templates/javadoc/methodsummary/html/included.erb +0 -12
- data/templates/javadoc/methodsummary/html/inherited.erb +0 -12
- data/templates/javadoc/methodsummary/html/summary.erb +0 -25
- data/templates/javadoc/mixins/html/header.erb +0 -5
- data/templates/javadoc/module/html/header.erb +0 -4
- data/templates/javadoc/source/html/main.erb +0 -15
- data/templates/javadoc/tags/html/header.erb +0 -5
- data/templates/javadoc/tags/html/see.erb +0 -8
- data/templates/javadoc/tags/html/tags.erb +0 -19
- data/templates/javadoc/visibilitygroup/html/header.erb +0 -5
@@ -253,8 +253,8 @@ module YARD
|
|
253
253
|
[:TkDOLLAR, TkUnknownChar, "\$"], #"
|
254
254
|
]
|
255
255
|
|
256
|
-
# {reading => token_class}
|
257
|
-
# {reading => [token_class, *opt]}
|
256
|
+
# { reading => token_class }
|
257
|
+
# { reading => [token_class, *opt] }
|
258
258
|
TkReading2Token = {}
|
259
259
|
TkSymbol2Token = {}
|
260
260
|
|
@@ -16,7 +16,7 @@ module YARD
|
|
16
16
|
if content.is_a? TokenList
|
17
17
|
@tokens = content.dup
|
18
18
|
elsif content.is_a? String
|
19
|
-
@tokens = TokenList.new(content)
|
19
|
+
@tokens = TokenList.new(content.gsub("\r", ""))
|
20
20
|
else
|
21
21
|
raise ArgumentError, "Invalid content for StatementList: #{content.inspect}:#{content.class}"
|
22
22
|
end
|
@@ -110,11 +110,12 @@ module YARD
|
|
110
110
|
#
|
111
111
|
# @param [RubyToken::Token] tk the token to process
|
112
112
|
def process_token(tk)
|
113
|
-
#p tk.text, @state, @level, @current_block, "<br/>"
|
113
|
+
# p tk.text, @state, @level, @current_block, "<br/>"
|
114
114
|
case @state
|
115
115
|
when :first_statement
|
116
116
|
return if process_initial_comment(tk)
|
117
117
|
return if @statement.empty? && [TkSPACE, TkNL, TkCOMMENT].include?(tk.class)
|
118
|
+
@comments_last_line = nil
|
118
119
|
return if process_simple_block_opener(tk)
|
119
120
|
push_token(tk)
|
120
121
|
return if process_complex_block_opener(tk)
|
@@ -175,15 +176,14 @@ module YARD
|
|
175
176
|
# @param [RubyToken::Token] tk the token to process
|
176
177
|
# @return [Boolean] whether or not +tk+ was processed as an initial comment
|
177
178
|
def process_initial_comment(tk)
|
178
|
-
|
179
|
-
|
180
|
-
# Two new-lines in a row will destroy any comment blocks
|
181
|
-
if @last_tk.class == TkNL && @before_last_tk &&
|
182
|
-
(@before_last_tk.class == TkNL || @before_last_tk.class == TkSPACE)
|
183
|
-
@comments = nil
|
184
|
-
return
|
179
|
+
if @statement.empty? && (@comments_last_line || 0) < tk.line_no - 2
|
180
|
+
@comments = nil
|
185
181
|
end
|
186
182
|
|
183
|
+
return unless tk.class == TkCOMMENT
|
184
|
+
return if !@statement.empty? && @comments
|
185
|
+
|
186
|
+
@comments = nil if @comments_last_line && @comments_last_line < tk.line_no - 1
|
187
187
|
@comments_line = tk.line_no unless @comments
|
188
188
|
|
189
189
|
# Remove the "#" and up to 1 space before the text
|
@@ -192,6 +192,7 @@ module YARD
|
|
192
192
|
@comments ||= []
|
193
193
|
@comments << tk.text.gsub(/^#+\s{0,1}/, '')
|
194
194
|
@comments.pop if @comments.size == 1 && @comments.first =~ /^\s*$/
|
195
|
+
@comments_last_line = tk.line_no
|
195
196
|
true
|
196
197
|
end
|
197
198
|
|
@@ -39,7 +39,6 @@ module YARD
|
|
39
39
|
:END => "END",
|
40
40
|
:alias => "alias",
|
41
41
|
:array => :lbracket,
|
42
|
-
:aref => :lbracket,
|
43
42
|
:arg_paren => :lparen,
|
44
43
|
:begin => "begin",
|
45
44
|
:blockarg => "&",
|
@@ -150,7 +149,8 @@ module YARD
|
|
150
149
|
[:kw, :op].each do |event|
|
151
150
|
module_eval(<<-eof, __FILE__, __LINE__ + 1)
|
152
151
|
def on_#{event}(tok)
|
153
|
-
unless @
|
152
|
+
unless @last_ns_token == [:kw, "def"] ||
|
153
|
+
(@tokens.last && @tokens.last[0] == :symbeg)
|
154
154
|
(@map[tok] ||= []) << [lineno, charno]
|
155
155
|
end
|
156
156
|
visit_ns_token(:#{event}, tok, true)
|
@@ -185,6 +185,7 @@ module YARD
|
|
185
185
|
def visit_ns_token(token, data, ast_token = false)
|
186
186
|
add_token(token, data)
|
187
187
|
ch = charno
|
188
|
+
@last_ns_token = [token, data]
|
188
189
|
@charno += data.length
|
189
190
|
@ns_charno = charno
|
190
191
|
if ast_token
|
@@ -205,7 +206,7 @@ module YARD
|
|
205
206
|
end
|
206
207
|
|
207
208
|
def on_body_stmt(*args)
|
208
|
-
args.first
|
209
|
+
args.compact.size == 1 ? args.first : AstNode.new(:list, args)
|
209
210
|
end
|
210
211
|
|
211
212
|
def on_assoc_new(*args)
|
@@ -224,6 +225,29 @@ module YARD
|
|
224
225
|
args.first
|
225
226
|
end
|
226
227
|
|
228
|
+
def on_aref(*args)
|
229
|
+
ll, lc = *@map[:aref].pop
|
230
|
+
sr = args.first.source_range.first..lc
|
231
|
+
lr = args.first.line_range.first..ll
|
232
|
+
AstNode.new(:aref, args, char: sr, line: lr)
|
233
|
+
end
|
234
|
+
|
235
|
+
def on_rbracket(tok)
|
236
|
+
(@map[:aref] ||= []) << [lineno, charno]
|
237
|
+
visit_ns_token(:rbracket, tok, false)
|
238
|
+
end
|
239
|
+
|
240
|
+
[:if_mod, :unless_mod, :while_mod].each do |kw|
|
241
|
+
node_class = AstNode.node_class_for(kw)
|
242
|
+
module_eval(<<-eof, __FILE__, __LINE__ + 1)
|
243
|
+
def on_#{kw}(*args)
|
244
|
+
sr = args.last.source_range.first..args.first.source_range.last
|
245
|
+
lr = args.last.line_range.first..args.first.line_range.last
|
246
|
+
#{node_class}.new(:#{kw}, args, line: lr, char: sr)
|
247
|
+
end
|
248
|
+
eof
|
249
|
+
end
|
250
|
+
|
227
251
|
def on_qwords_new
|
228
252
|
visit_event AstNode.new(:qwords_literal, [])
|
229
253
|
end
|
@@ -239,6 +263,11 @@ module YARD
|
|
239
263
|
def on_string_content(*args)
|
240
264
|
AstNode.new(:string_content, args, listline: lineno..lineno, listchar: charno..charno)
|
241
265
|
end
|
266
|
+
|
267
|
+
def on_rescue(exc, *args)
|
268
|
+
exc = AstNode.new(:list, exc) if exc
|
269
|
+
visit_event AstNode.new(:rescue, [exc, *args])
|
270
|
+
end
|
242
271
|
|
243
272
|
def on_void_stmt
|
244
273
|
AstNode.new(:void_stmt, [], line: lineno..lineno, char: charno...charno)
|
@@ -3,19 +3,51 @@ require 'continuation' unless RUBY18
|
|
3
3
|
|
4
4
|
module YARD
|
5
5
|
module Parser
|
6
|
+
# Raised when an object is recognized but cannot be documented. This
|
7
|
+
# generally occurs when the Ruby syntax used to declare an object is
|
8
|
+
# too dynamic in nature.
|
6
9
|
class UndocumentableError < Exception; end
|
10
|
+
|
11
|
+
# Raised when the parser sees a Ruby syntax error
|
7
12
|
class ParserSyntaxError < UndocumentableError; end
|
13
|
+
|
14
|
+
# A LoadOrderError occurs when a handler needs to modify a
|
15
|
+
# {CodeObjects::NamespaceObject} (usually by adding a child to it)
|
16
|
+
# that has not yet been resolved.
|
17
|
+
#
|
18
|
+
# @see Handers::Base#ensure_loaded!
|
8
19
|
class LoadOrderError < Exception; end
|
9
20
|
|
10
|
-
# Responsible for parsing a source file into the namespace
|
21
|
+
# Responsible for parsing a source file into the namespace. Parsing
|
22
|
+
# also invokes handlers to process the parsed statements and generate
|
23
|
+
# any code objects that may be recognized.
|
24
|
+
#
|
25
|
+
# @see Handlers::Base
|
26
|
+
# @see CodeObjects::Base
|
11
27
|
class SourceParser
|
12
28
|
class << self
|
29
|
+
# The default parser type to use for blocks of code. Change this
|
30
|
+
# attribute to apply a new parser type for all newly parsed
|
31
|
+
# blocks of code.
|
32
|
+
#
|
33
|
+
# @return [Symbol] the parser type
|
13
34
|
attr_accessor :parser_type
|
14
35
|
|
36
|
+
# Sets the parser and makes sure it's a valid type
|
37
|
+
#
|
38
|
+
# @param [Symbol] value the new parser type
|
39
|
+
# @return [nil]
|
15
40
|
def parser_type=(value)
|
16
41
|
@parser_type = validated_parser_type(value)
|
17
42
|
end
|
18
43
|
|
44
|
+
# Parses a path or set of paths
|
45
|
+
#
|
46
|
+
# @param [String, Array<String>] paths a path, glob, or list of paths to
|
47
|
+
# parse
|
48
|
+
# @param [Fixnum] level the logger level to use during parsing. See
|
49
|
+
# {YARD::Logger}
|
50
|
+
# @return the parser object that was used to parse the source.
|
19
51
|
def parse(paths = "lib/**/*.rb", level = log.level)
|
20
52
|
log.debug("Parsing #{paths} with `#{parser_type}` parser")
|
21
53
|
files = [paths].flatten.map {|p| p.include?("*") ? Dir[p] : p }.flatten
|
@@ -25,21 +57,43 @@ module YARD
|
|
25
57
|
end
|
26
58
|
end
|
27
59
|
|
60
|
+
# Parses a string +content+
|
61
|
+
#
|
62
|
+
# @param [String] content the block of code to parse
|
63
|
+
# @param [Symbol] ptype the parser type to use. See {parser_type}.
|
64
|
+
# @return the parser object that was used to parse +content+
|
28
65
|
def parse_string(content, ptype = parser_type)
|
29
66
|
new(ptype).parse(StringIO.new(content))
|
30
67
|
end
|
31
68
|
|
69
|
+
# Tokenizes but does not parse the block of code
|
70
|
+
#
|
71
|
+
# @param [String] content the block of code to tokenize
|
72
|
+
# @param [Symbol] ptype the parser type to use. See {parser_type}.
|
73
|
+
# @return [Array] a list of tokens
|
32
74
|
def tokenize(content, ptype = parser_type)
|
33
75
|
new(ptype).tokenize(content)
|
34
76
|
end
|
35
77
|
|
78
|
+
# Returns the validated parser type. Basically, enforces that :ruby
|
79
|
+
# type is never set from Ruby 1.8
|
80
|
+
#
|
81
|
+
# @param [Symbol] type the parser type to set
|
82
|
+
# @return [Symbol] the validated parser type
|
36
83
|
def validated_parser_type(type)
|
37
84
|
RUBY18 && type == :ruby ? :ruby18 : type
|
38
85
|
end
|
39
86
|
|
40
87
|
private
|
41
88
|
|
89
|
+
# Parses a list of files in a queue. If a {LoadOrderError} is caught,
|
90
|
+
# the file is moved to the back of the queue with a Continuation object
|
91
|
+
# that can continue processing the file.
|
92
|
+
#
|
93
|
+
# @param [Array<String>] files a list of files to queue for parsing
|
94
|
+
# @return [nil]
|
42
95
|
def parse_in_order(*files)
|
96
|
+
files = files.sort_by {|x| x.length if x }
|
43
97
|
while file = files.shift
|
44
98
|
begin
|
45
99
|
if file.is_a?(Array) && file.last.is_a?(Continuation)
|
@@ -59,19 +113,28 @@ module YARD
|
|
59
113
|
|
60
114
|
self.parser_type = :ruby
|
61
115
|
|
62
|
-
|
116
|
+
# The filename being parsed by the parser.
|
117
|
+
attr_reader :file
|
118
|
+
|
119
|
+
# The parser type associated with the parser instance. This should
|
120
|
+
# be set by the {#initialize constructor}.
|
121
|
+
attr_reader :parser_type
|
63
122
|
|
123
|
+
# Creates a new parser object for code parsing with a specific parser type.
|
124
|
+
#
|
125
|
+
# @param [Symbol] parser_type the parser type to use
|
126
|
+
# @param [Boolean] load_order_errors whether or not to raise the {LoadOrderError}
|
64
127
|
def initialize(parser_type = SourceParser.parser_type, load_order_errors = false)
|
65
128
|
@load_order_errors = load_order_errors
|
66
129
|
@file = '(stdin)'
|
67
130
|
self.parser_type = parser_type
|
68
131
|
end
|
69
132
|
|
70
|
-
|
71
|
-
#
|
72
|
-
# analysis information about it.
|
133
|
+
# The main parser method. This should not be called directly. Instead,
|
134
|
+
# use the class methods {parse} and {parse_string}.
|
73
135
|
#
|
74
136
|
# @param [String, #read, Object] content the source file to parse
|
137
|
+
# @return the parser object used to parse the source
|
75
138
|
def parse(content = __FILE__)
|
76
139
|
case content
|
77
140
|
when String
|
@@ -91,6 +154,10 @@ module YARD
|
|
91
154
|
log.warn(e.message.capitalize)
|
92
155
|
end
|
93
156
|
|
157
|
+
# Tokenizes but does not parse the block of code using the current {#parser_type}
|
158
|
+
#
|
159
|
+
# @param [String] content the block of code to tokenize
|
160
|
+
# @return [Array] a list of tokens
|
94
161
|
def tokenize(content)
|
95
162
|
case parser_type
|
96
163
|
when :c
|
@@ -106,6 +173,8 @@ module YARD
|
|
106
173
|
|
107
174
|
private
|
108
175
|
|
176
|
+
# Runs a {Handlers::Processor} object to post process the parsed statements.
|
177
|
+
# @return [nil]
|
109
178
|
def post_process
|
110
179
|
post = Handlers::Processor.new(@file, @load_order_errors, @parser_type)
|
111
180
|
post.process(@parser.enumerator)
|
@@ -115,6 +184,10 @@ module YARD
|
|
115
184
|
@parser_type = self.class.validated_parser_type(value)
|
116
185
|
end
|
117
186
|
|
187
|
+
# Guesses the parser type to use depending on the file extension.
|
188
|
+
#
|
189
|
+
# @param [String] filename the filename to use to guess the parser type
|
190
|
+
# @return [Symbol] a parser type that matches the filename
|
118
191
|
def parser_type_for_filename(filename)
|
119
192
|
case (File.extname(filename)[1..-1] || "").downcase
|
120
193
|
when "c", "cpp", "cxx"
|
@@ -124,6 +197,10 @@ module YARD
|
|
124
197
|
end
|
125
198
|
end
|
126
199
|
|
200
|
+
# Selects a parser to use to parse +content+.
|
201
|
+
#
|
202
|
+
# @param [String] content the block of code to parse
|
203
|
+
# @return the resulting parser object
|
127
204
|
def parse_statements(content)
|
128
205
|
case parser_type
|
129
206
|
when :c
|
@@ -4,13 +4,42 @@ require 'rake/tasklib'
|
|
4
4
|
module YARD
|
5
5
|
module Rake
|
6
6
|
|
7
|
+
# The rake task to run {CLI::Yardoc} and generate documentation.
|
7
8
|
class YardocTask < ::Rake::TaskLib
|
9
|
+
# The name of the task
|
10
|
+
# @return [String] the task name
|
8
11
|
attr_accessor :name
|
12
|
+
|
13
|
+
# Options to pass to {CLI::Yardoc}
|
14
|
+
# @return [Hash] the options passed to the commandline utility
|
9
15
|
attr_accessor :options
|
16
|
+
|
17
|
+
# The Ruby source files (and any extra documentation files separated by '-')
|
18
|
+
# to process
|
19
|
+
# @return [Array<String>] a list of files
|
10
20
|
attr_accessor :files
|
11
|
-
|
21
|
+
|
22
|
+
# Runs a +Proc+ before the task
|
23
|
+
# @return [Proc] a proc to call before running the task
|
24
|
+
attr_accessor :before
|
25
|
+
|
26
|
+
# Runs a +Proc+ after the task
|
27
|
+
# @return [Proc] a proc to call after running the task
|
28
|
+
attr_accessor :after
|
29
|
+
|
30
|
+
# @return [Proc] an optional lambda to run against all objects being
|
31
|
+
# generated. Any object that the lambda returns false for will be
|
32
|
+
# excluded from documentation.
|
33
|
+
# @see Verifier
|
34
|
+
attr_accessor :verifier
|
12
35
|
|
13
|
-
|
36
|
+
# Creates a new task with name +name+.
|
37
|
+
#
|
38
|
+
# @param [String, Symbol] name the name of the rake task
|
39
|
+
# @yield a block to allow any options to be modified on the task
|
40
|
+
# @yieldparam [YardocTask] _self the task object to allow any parameters
|
41
|
+
# to be changed.
|
42
|
+
def initialize(name = :yard)
|
14
43
|
@name = name
|
15
44
|
@options = []
|
16
45
|
@files = []
|
@@ -22,11 +51,17 @@ module YARD
|
|
22
51
|
define
|
23
52
|
end
|
24
53
|
|
54
|
+
protected
|
55
|
+
|
56
|
+
# Defines the rake task
|
57
|
+
# @return [nil]
|
25
58
|
def define
|
26
59
|
desc "Generate YARD Documentation"
|
27
60
|
task(name) do
|
28
61
|
before.call if before.is_a?(Proc)
|
29
|
-
YARD::CLI::Yardoc.
|
62
|
+
yardoc = YARD::CLI::Yardoc.new
|
63
|
+
yardoc.options[:verifier] = verifier if verifier
|
64
|
+
yardoc.run *(options + files)
|
30
65
|
after.call if after.is_a?(Proc)
|
31
66
|
end
|
32
67
|
end
|
data/lib/yard/registry.rb
CHANGED
@@ -2,6 +2,18 @@ require 'singleton'
|
|
2
2
|
require 'find'
|
3
3
|
|
4
4
|
module YARD
|
5
|
+
# The +Registry+ is the centralized data store for all {CodeObjects} created
|
6
|
+
# during parsing. The storage is a key value store with the object's path
|
7
|
+
# (see {CodeObjects::Base#path}) as the key and the object itself as the value.
|
8
|
+
# Object paths must be unique to be stored in the Registry. All lookups for
|
9
|
+
# objects are done on the singleton Registry instance using the {Registry#at}
|
10
|
+
# or {Registry#resolve} methods.
|
11
|
+
#
|
12
|
+
# The registry is saved to a "yardoc" file, which can be loaded back to
|
13
|
+
# perform any lookups.
|
14
|
+
#
|
15
|
+
# This class is a singleton class. Any method called on the class will be
|
16
|
+
# delegated to the instance.
|
5
17
|
class Registry
|
6
18
|
DEFAULT_YARDOC_FILE = ".yardoc"
|
7
19
|
|
@@ -10,17 +22,43 @@ module YARD
|
|
10
22
|
@objects = {}
|
11
23
|
|
12
24
|
class << self
|
25
|
+
# Holds the objects cache. This attribute should never be accessed
|
26
|
+
# directly.
|
27
|
+
# @return [Array<CodeObjects::Base>] the objects cache
|
13
28
|
attr_reader :objects
|
14
29
|
|
30
|
+
# Clears the registry and cache
|
31
|
+
# @return [nil]
|
15
32
|
def clear
|
16
33
|
instance.clear
|
17
34
|
objects.clear
|
18
35
|
end
|
19
36
|
end
|
20
37
|
|
38
|
+
# Gets/sets the yardoc filename
|
39
|
+
# @return [String] the yardoc filename
|
40
|
+
# @see DEFAULT_YARDOC_FILE
|
21
41
|
attr_accessor :yardoc_file
|
42
|
+
|
43
|
+
# The assumed types of a list of paths
|
44
|
+
# @return [{String => Symbol}] a set of unresolved paths and their assumed type
|
22
45
|
attr_reader :proxy_types
|
23
46
|
|
47
|
+
# Loads the registry and/or parses a list of files
|
48
|
+
#
|
49
|
+
# @example Loads the yardoc file or parses files 'a', 'b' and 'c' (but not both)
|
50
|
+
# Registry.load(['a', 'b', 'c'])
|
51
|
+
# @example Reparses files 'a' and 'b' regardless if yardoc file exists
|
52
|
+
# Registry.load(['a', 'b'], true)
|
53
|
+
# @param [String, Array] files if +files+ is an Array, it should represent
|
54
|
+
# a list of files that YARD should parse into the registry. If reload is
|
55
|
+
# set to false and the yardoc file already exists, these files are skipped.
|
56
|
+
# If files is a String, it should represent the yardoc file to load
|
57
|
+
# into the registry.
|
58
|
+
# @param [Boolean] reload if reload is false and a yardoc file already
|
59
|
+
# exists, any files passed in will be ignored.
|
60
|
+
# @return [Boolean] true if the registry was successfully loaded
|
61
|
+
# @raise [ArgumentError] if files is not a String or Array
|
24
62
|
def load(files = [], reload = false)
|
25
63
|
if files.is_a?(Array)
|
26
64
|
if File.exists?(yardoc_file) && !reload
|
@@ -39,6 +77,10 @@ module YARD
|
|
39
77
|
end
|
40
78
|
end
|
41
79
|
|
80
|
+
# Loads a yardoc file directly
|
81
|
+
#
|
82
|
+
# @param [String] file the yardoc file to load.
|
83
|
+
# @return [nil]
|
42
84
|
def load_yardoc(file = yardoc_file)
|
43
85
|
return false unless File.exists?(file)
|
44
86
|
ns, pt = *Marshal.load(IO.read(file))
|
@@ -46,11 +88,27 @@ module YARD
|
|
46
88
|
proxy_types.update(pt)
|
47
89
|
end
|
48
90
|
|
91
|
+
# Saves the registry to +file+
|
92
|
+
#
|
93
|
+
# @param [String] file the yardoc file to save to
|
94
|
+
# @return [Boolean] true if the file was saved
|
49
95
|
def save(file = yardoc_file)
|
50
|
-
File.open(file, "
|
96
|
+
File.open(file, "wb") {|f| Marshal.dump([@namespace, @proxy_types], f) }
|
51
97
|
true
|
52
98
|
end
|
53
99
|
|
100
|
+
# Returns all objects in the registry that match one of the types provided
|
101
|
+
# in the +types+ list (if +types+ is provided).
|
102
|
+
#
|
103
|
+
# @example Returns all objects
|
104
|
+
# Registry.all
|
105
|
+
# @example Returns all classes and modules
|
106
|
+
# Registry.all(:class, :module)
|
107
|
+
# @param [Array<Symbol>] types an optional list of types to narrow the
|
108
|
+
# objects down by. Equivalent to performing a select:
|
109
|
+
# +Registry.all.select {|o| types.include(o.type) }+
|
110
|
+
# @return [Array<CodeObjects::Base>] the list of objects found
|
111
|
+
# @see CodeObjects::Base#type
|
54
112
|
def all(*types)
|
55
113
|
namespace.values.select do |obj|
|
56
114
|
if types.empty?
|
@@ -64,37 +122,83 @@ module YARD
|
|
64
122
|
end + (types.include?(:root) ? [root] : [])
|
65
123
|
end
|
66
124
|
|
125
|
+
# Returns the paths of all of the objects in the registry.
|
126
|
+
# @return [Array<String>] all of the paths in the registry.
|
67
127
|
def paths
|
68
128
|
namespace.keys.map {|k| k.to_s }
|
69
129
|
end
|
70
|
-
|
130
|
+
|
131
|
+
# Returns the object at a specific path.
|
132
|
+
# @param [String, :root] path the pathname to look for. If +path+ is +root+,
|
133
|
+
# returns the {#root} object.
|
134
|
+
# @return [CodeObjects::Base] the object at path
|
135
|
+
# @return [nil] if no object is found
|
71
136
|
def at(path) path.to_s.empty? ? root : namespace[path] end
|
72
137
|
alias_method :[], :at
|
73
138
|
|
139
|
+
# The root namespace object.
|
140
|
+
# @return [CodeObjects::RootObject] the root object in the namespace
|
74
141
|
def root; namespace[:root] end
|
75
142
|
|
143
|
+
# Deletes an object from the registry
|
144
|
+
# @param [CodeObjects::Base] object the object to remove
|
145
|
+
# @return [nil]
|
76
146
|
def delete(object)
|
77
147
|
namespace.delete(object.path)
|
78
148
|
self.class.objects.delete(object.path)
|
79
149
|
end
|
80
150
|
|
151
|
+
# Clears the registry
|
152
|
+
# @return [nil]
|
81
153
|
def clear
|
82
154
|
@namespace = SymbolHash.new
|
83
155
|
@namespace[:root] = CodeObjects::RootObject.new(nil, :root)
|
84
156
|
@proxy_types = {}
|
85
157
|
end
|
86
158
|
|
159
|
+
# Creates the Registry
|
160
|
+
# @return [Registry]
|
87
161
|
def initialize
|
88
162
|
@yardoc_file = DEFAULT_YARDOC_FILE
|
89
163
|
clear
|
90
164
|
end
|
91
165
|
|
166
|
+
# Registers a new object with the registry
|
167
|
+
#
|
168
|
+
# @param [CodeObjects::Base] object the object to register
|
169
|
+
# @return [CodeObjects::Base] the registered object
|
92
170
|
def register(object)
|
93
171
|
self.class.objects[object.path] = object
|
94
172
|
return if object.is_a?(CodeObjects::Proxy)
|
95
173
|
namespace[object.path] = object
|
96
174
|
end
|
97
175
|
|
176
|
+
# Attempts to find an object by name starting at +namespace+, performing
|
177
|
+
# a lookup similar to Ruby's method of resolving a constant in a namespace.
|
178
|
+
#
|
179
|
+
# @example Looks for instance method #reverse starting from A::B::C
|
180
|
+
# Registry.resolve(P("A::B::C"), "#reverse")
|
181
|
+
# @example Looks for a constant in the root namespace
|
182
|
+
# Registry.resolve(nil, 'CONSTANT')
|
183
|
+
# @example Looks for a class method respecting the inheritance tree
|
184
|
+
# Registry.resolve(myclass, 'mymethod', true)
|
185
|
+
# @example Looks for a constant but returns a proxy if not found
|
186
|
+
# Registry.resolve(P('A::B::C'), 'D', false, true) # => #<yardoc proxy A::B::C::D>
|
187
|
+
# @example Looks for a complex path from a namespace
|
188
|
+
# Registry.resolve(P('A::B'), 'B::D') # => #<yardoc class A::B::D>
|
189
|
+
# @param [CodeObjects::NamespaceObject, nil] namespace the starting namespace
|
190
|
+
# (module or class). If +nil+ or +:root+, starts from the {#root} object.
|
191
|
+
# @param [String, Symbol] name the name (or complex path) to look for from
|
192
|
+
# +namespace+.
|
193
|
+
# @param [Boolean] inheritance Follows inheritance chain (mixins, superclass)
|
194
|
+
# when performing name resolution if set to +true+.
|
195
|
+
# @param [Boolean] proxy_fallback If +true+, returns a proxy representing
|
196
|
+
# the unresolved path (namespace + name) if no object is found.
|
197
|
+
# @return [CodeObjects::Base] the object if it is found
|
198
|
+
# @return [CodeObjects::Proxy] a Proxy representing the object if
|
199
|
+
# +proxy_fallback+ is +true+.
|
200
|
+
# @return [nil] if +proxy_fallback+ is +false+ and no object was found.
|
201
|
+
# @see P
|
98
202
|
def resolve(namespace, name, inheritance = false, proxy_fallback = false)
|
99
203
|
if namespace.is_a?(CodeObjects::Proxy)
|
100
204
|
return proxy_fallback ? CodeObjects::Proxy.new(namespace, name) : nil
|
@@ -143,8 +247,14 @@ module YARD
|
|
143
247
|
|
144
248
|
private
|
145
249
|
|
250
|
+
# The internal namespace hash
|
251
|
+
# @return [Hash{String => CodeObjects::Base}] the path/object hash
|
146
252
|
attr_accessor :namespace
|
147
253
|
|
254
|
+
# Attempts to resolve a name in a namespace
|
255
|
+
#
|
256
|
+
# @param [CodeObjects::NamespaceObject] namespace the starting namespace
|
257
|
+
# @param [String] name the name to look for
|
148
258
|
def partial_resolve(namespace, name)
|
149
259
|
[CodeObjects::NSEP, CodeObjects::CSEP, ''].each do |s|
|
150
260
|
next if s.empty? && name =~ /^\w/
|