yard 0.9.28 → 0.9.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +139 -1
- data/LEGAL +29 -1
- data/README.md +29 -25
- data/docs/GettingStarted.md +41 -15
- data/docs/Parser.md +17 -42
- data/docs/Tags.md +6 -6
- data/docs/Templates.md +5 -4
- data/docs/WhatsNew.md +61 -9
- data/docs/templates/default/yard_tags/html/setup.rb +1 -1
- data/lib/yard/autoload.rb +20 -1
- data/lib/yard/cli/command.rb +1 -1
- data/lib/yard/cli/diff.rb +7 -2
- data/lib/yard/cli/yardoc.rb +1 -1
- data/lib/yard/code_objects/base.rb +6 -2
- data/lib/yard/code_objects/extra_file_object.rb +1 -0
- data/lib/yard/code_objects/macro_object.rb +0 -1
- data/lib/yard/code_objects/proxy.rb +1 -1
- data/lib/yard/docstring_parser.rb +1 -2
- data/lib/yard/handlers/base.rb +23 -1
- data/lib/yard/handlers/processor.rb +1 -1
- data/lib/yard/handlers/rbs/attribute_handler.rb +79 -0
- data/lib/yard/handlers/rbs/base.rb +38 -0
- data/lib/yard/handlers/rbs/constant_handler.rb +18 -0
- data/lib/yard/handlers/rbs/method_handler.rb +327 -0
- data/lib/yard/handlers/rbs/mixin_handler.rb +20 -0
- data/lib/yard/handlers/rbs/namespace_handler.rb +26 -0
- data/lib/yard/handlers/ruby/attribute_handler.rb +7 -4
- data/lib/yard/handlers/ruby/constant_handler.rb +24 -6
- data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +1 -1
- data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +2 -1
- data/lib/yard/handlers/ruby/mixin_handler.rb +13 -6
- data/lib/yard/handlers/ruby/visibility_handler.rb +14 -1
- data/lib/yard/i18n/locale.rb +2 -2
- data/lib/yard/i18n/message.rb +2 -2
- data/lib/yard/i18n/messages.rb +1 -1
- data/lib/yard/i18n/pot_generator.rb +2 -2
- data/lib/yard/logging.rb +116 -61
- data/lib/yard/open_struct.rb +67 -0
- data/lib/yard/options.rb +1 -1
- data/lib/yard/parser/rbs/rbs_parser.rb +325 -0
- data/lib/yard/parser/rbs/statement.rb +75 -0
- data/lib/yard/parser/ruby/ast_node.rb +5 -4
- data/lib/yard/parser/ruby/legacy/irb/slex.rb +19 -1
- data/lib/yard/parser/ruby/legacy/ruby_lex.rb +20 -5
- data/lib/yard/parser/ruby/ruby_parser.rb +117 -26
- data/lib/yard/parser/source_parser.rb +7 -7
- data/lib/yard/registry_resolver.rb +9 -1
- data/lib/yard/rubygems/specification.rb +1 -1
- data/lib/yard/server/commands/base.rb +2 -2
- data/lib/yard/server/commands/library_command.rb +8 -8
- data/lib/yard/server/commands/static_file_helpers.rb +1 -2
- data/lib/yard/server/http_utils.rb +512 -0
- data/lib/yard/server/library_version.rb +1 -1
- data/lib/yard/server/rack_adapter.rb +13 -5
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +168 -88
- data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +203 -12
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +1 -17
- data/lib/yard/server/templates/default/method_details/html/permalink.erb +4 -2
- data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +3 -3
- data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +2 -3
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +22 -16
- data/lib/yard/tags/default_factory.rb +1 -0
- data/lib/yard/tags/directives.rb +7 -1
- data/lib/yard/tags/library.rb +3 -3
- data/lib/yard/tags/overload_tag.rb +2 -1
- data/lib/yard/tags/tag.rb +4 -3
- data/lib/yard/tags/types_explainer.rb +6 -5
- data/lib/yard/templates/engine.rb +0 -1
- data/lib/yard/templates/helpers/base_helper.rb +1 -1
- data/lib/yard/templates/helpers/html_helper.rb +21 -6
- data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +6 -1
- data/lib/yard/templates/helpers/markup/hybrid_markdown.rb +2147 -0
- data/lib/yard/templates/helpers/markup/rdoc_markup.rb +2 -0
- data/lib/yard/templates/helpers/markup_helper.rb +4 -2
- data/lib/yard/templates/template_options.rb +0 -1
- data/lib/yard/version.rb +1 -1
- data/po/ja.po +101 -101
- data/templates/default/fulldoc/html/css/common.css +1 -1
- data/templates/default/fulldoc/html/css/full_list.css +201 -53
- data/templates/default/fulldoc/html/css/style.css +991 -399
- data/templates/default/fulldoc/html/frames.erb +9 -4
- data/templates/default/fulldoc/html/full_list.erb +8 -5
- data/templates/default/fulldoc/html/js/app.js +799 -312
- data/templates/default/fulldoc/html/js/full_list.js +332 -214
- data/templates/default/fulldoc/html/setup.rb +10 -2
- data/templates/default/layout/html/headers.erb +1 -1
- data/templates/default/layout/html/layout.erb +3 -1
- data/templates/default/method/html/header.erb +3 -3
- data/templates/default/module/html/defines.erb +3 -3
- data/templates/default/module/html/inherited_methods.erb +1 -0
- data/templates/default/module/html/method_summary.erb +8 -0
- data/templates/default/module/setup.rb +20 -0
- data/templates/default/onefile/html/headers.erb +2 -0
- data/templates/default/onefile/html/layout.erb +3 -4
- data/templates/default/tags/html/example.erb +2 -2
- data/templates/default/tags/html/option.erb +1 -1
- data/templates/guide/fulldoc/html/css/style.css +347 -97
- data/templates/guide/fulldoc/html/js/app.js +61 -33
- data/templates/guide/layout/html/layout.erb +69 -72
- metadata +21 -60
- data/.dockerignore +0 -2
- data/.gitattributes +0 -4
- data/.github/FUNDING.yml +0 -3
- data/.github/ISSUE_TEMPLATE.md +0 -33
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -12
- data/.github/workflows/ci.yml +0 -30
- data/.github/workflows/gem.yml +0 -19
- data/.gitignore +0 -14
- data/.rspec +0 -2
- data/.rubocop.yml +0 -112
- data/CODE_OF_CONDUCT.md +0 -15
- data/CONTRIBUTING.md +0 -140
- data/Dockerfile.samus +0 -28
- data/Gemfile +0 -34
- data/Rakefile +0 -36
- data/SECURITY.md +0 -26
- data/benchmarks/builtins_vs_eval.rb +0 -24
- data/benchmarks/concat_vs_join.rb +0 -13
- data/benchmarks/erb_vs_erubis.rb +0 -54
- data/benchmarks/format_args.rb +0 -47
- data/benchmarks/generation.rb +0 -38
- data/benchmarks/marshal_vs_dbm.rb +0 -64
- data/benchmarks/parsing.rb +0 -46
- data/benchmarks/pathname_vs_string.rb +0 -51
- data/benchmarks/rdoc_vs_yardoc.rb +0 -11
- data/benchmarks/registry_store_types.rb +0 -49
- data/benchmarks/ri_vs_yri.rb +0 -19
- data/benchmarks/ripper_parser.rb +0 -13
- data/benchmarks/splat_vs_flatten.rb +0 -13
- data/benchmarks/template_erb.rb +0 -23
- data/benchmarks/template_format.rb +0 -7
- data/benchmarks/template_profile.rb +0 -18
- data/benchmarks/yri_cache.rb +0 -20
- data/samus.json +0 -49
- data/tasks/prepare_tag.rake +0 -45
- data/tasks/update_error_map.rake +0 -53
- data/yard.gemspec +0 -25
data/docs/WhatsNew.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# @title What's New?
|
|
2
2
|
|
|
3
|
+
# What's New in 0.9.x?
|
|
4
|
+
|
|
5
|
+
## Support for Ruby Signature Files (.rbs) (0.9.40)
|
|
6
|
+
|
|
7
|
+
YARD now supports parsing Ruby signature files (.rbs) with full docstring support. This means you can write your documentation in `.rbs` files and have it show up in generated documentation, and use `.rbs` files alongside `.rb` sources to supplement type and API information.
|
|
8
|
+
|
|
9
|
+
## New built-in Markdown renderer (0.9.40)
|
|
10
|
+
|
|
11
|
+
YARD now ships with a built-in Markdown renderer (`YARD::Templates::Helpers::Markup::HybridMarkdown`)
|
|
12
|
+
that requires **no external gems**. It supports a practical subset of GitHub Flavored Markdown (GFM)
|
|
13
|
+
as well as common RDoc markup forms, including:
|
|
14
|
+
|
|
15
|
+
- Headings (`#`, `=`)
|
|
16
|
+
- Fenced code blocks (`` ``` `` and `~~~`) as well as RDoc formatted `+text+` blocks.
|
|
17
|
+
- Tables, blockquotes, and thematic breaks
|
|
18
|
+
- Ordered and unordered lists (including RDoc-style)
|
|
19
|
+
- Inline emphasis, code, links, and images
|
|
20
|
+
- HTML passthrough blocks
|
|
21
|
+
|
|
22
|
+
This renderer is the **default** for both the `rdoc` and `markdown` markup types—no gem
|
|
23
|
+
installation required. If an optional provider gem (e.g. `redcarpet`, `kramdown`,
|
|
24
|
+
`commonmarker`) is installed and selected, YARD will use it instead for extra features such
|
|
25
|
+
as custom extensions or stricter spec compliance.
|
|
26
|
+
|
|
27
|
+
## `#-` comment block separators (0.9.40)
|
|
28
|
+
|
|
29
|
+
YARD now recognizes a trailing `#-` line as a separator between comment
|
|
30
|
+
blocks. This is useful when you want to keep a file header comment at the top
|
|
31
|
+
of a Ruby file without having that header attach itself to the first class,
|
|
32
|
+
module or method in the file.
|
|
33
|
+
|
|
34
|
+
For example:
|
|
35
|
+
|
|
36
|
+
# Copyright (c) Example Corp
|
|
37
|
+
# This file defines support code shared by the client.
|
|
38
|
+
#-
|
|
39
|
+
|
|
40
|
+
class Client
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
In the example above, the file header stays disconnected from `Client`.
|
|
44
|
+
Note that `# -` does **not** act as a separator; only an attached `#-`
|
|
45
|
+
line has this behavior.
|
|
46
|
+
|
|
47
|
+
## Ruby 4.x support (0.9.39)
|
|
48
|
+
|
|
49
|
+
Added support for Ruby 4.x along with new syntaxes.
|
|
50
|
+
|
|
51
|
+
## Other changes
|
|
52
|
+
|
|
53
|
+
See the [CHANGELOG](CHANGELOG.md) for a full list of changes in 0.9.x.
|
|
54
|
+
|
|
3
55
|
# What's New in 0.8.x?
|
|
4
56
|
|
|
5
57
|
1. **Directives (new behavioural tag syntax)** (0.8.0)
|
|
@@ -92,7 +144,7 @@ methods are defined dynamically and not associated with any code.
|
|
|
92
144
|
#### New `@!parse` directive to parse Ruby code
|
|
93
145
|
|
|
94
146
|
A new {tag:!parse} directive was added that allows a developer to have
|
|
95
|
-
YARD parse code that might not necessarily be
|
|
147
|
+
YARD parse code that might not necessarily be parsable in its original
|
|
96
148
|
form. This is useful when using `instance_eval` and other dynamic
|
|
97
149
|
meta-programming techniques to define methods or perform functionality.
|
|
98
150
|
For instance, a common case of the "self.included" callback in module
|
|
@@ -171,7 +223,7 @@ only mixins inside of a "Foo::Bar" namespace by doing:
|
|
|
171
223
|
YARD now ships with the beginnings of internationalization support
|
|
172
224
|
for translating documentation into multiple languages. The
|
|
173
225
|
`yard i18n` command now allows you to generate ".pot" and ultimately
|
|
174
|
-
".po" files for translation with [gettext](
|
|
226
|
+
".po" files for translation with [gettext](https://www.gnu.org/software/gettext).
|
|
175
227
|
|
|
176
228
|
Note that this tool is a small step in the larger transition for
|
|
177
229
|
proper I18n support in YARD. We still have to add proper gettext
|
|
@@ -283,7 +335,7 @@ above example would be:
|
|
|
283
335
|
But note that `--query` does not work when YARD is in "safe mode"
|
|
284
336
|
due to security concerns, whereas `--api` works in either mode.
|
|
285
337
|
This enables `--api` to function on remote documentation sites like
|
|
286
|
-
[rubydoc.info](
|
|
338
|
+
[rubydoc.info](https://rubydoc.info).
|
|
287
339
|
|
|
288
340
|
## Added `--non-transitive-tag` to disable transitive tag (0.8.3)
|
|
289
341
|
|
|
@@ -307,7 +359,7 @@ with `yard server -B PORT` or `yard server --bind PORT`.
|
|
|
307
359
|
|
|
308
360
|
Support for the AsciiDoc markup type is now introduced using the `asciidoc`
|
|
309
361
|
markup type (`yard doc -m asciidoc`). Requires the
|
|
310
|
-
[asciidoctor](
|
|
362
|
+
[asciidoctor](https://rubygems.org/gems/asciidoctor) RubyGem library to be
|
|
311
363
|
installed before running YARD.
|
|
312
364
|
|
|
313
365
|
## Added `yard markups` command to list available markup types (0.8.6)
|
|
@@ -645,7 +697,7 @@ templates. To serve documentation for installed gems:
|
|
|
645
697
|
will do this for you on-the-fly. It is therefore possible to speed up your
|
|
646
698
|
gem installs by using `gem install GEMNAME --no-rdoc` without repercussion.
|
|
647
699
|
You can also add this switch to your `~/.gemrc` file so that you don't need
|
|
648
|
-
to re-type it each time. See [this link](
|
|
700
|
+
to re-type it each time. See [this link](https://stackoverflow.com/questions/1789376/how-do-i-make-no-ri-no-rdoc-the-default-for-gem-install)
|
|
649
701
|
for exact instructions.</span>
|
|
650
702
|
|
|
651
703
|
## Groups support for method listing (0.6.0)
|
|
@@ -718,7 +770,7 @@ regular diffing tells you which lines have been added/removed in a file,
|
|
|
718
770
|
object diffing allows you to see what classes/methods/modules have been
|
|
719
771
|
added/removed between versions of a codebase.
|
|
720
772
|
|
|
721
|
-
For an overview of how to use `yard diff`, see [YARD Object Oriented Diffing](
|
|
773
|
+
For an overview of how to use `yard diff`, see [YARD Object Oriented Diffing](https://gnuu.org/2010/06/26/yard-object-oriented-diffing/).
|
|
722
774
|
|
|
723
775
|
## `yard stats` to display statistics and undocumented objects (0.6.0)
|
|
724
776
|
|
|
@@ -902,7 +954,7 @@ Support for documenting native Ruby C code (0.5.0)
|
|
|
902
954
|
|
|
903
955
|
It is now possible to document native Ruby extensions with YARD with a new
|
|
904
956
|
C parser mostly borrowed from RDoc. This enables the ability to document
|
|
905
|
-
Ruby's core and stdlibs which will be hosted on
|
|
957
|
+
Ruby's core and stdlibs which will be hosted on https://yardoc.org/docs. In
|
|
906
958
|
addition, the .yardoc dump for the Ruby-core classes will become available
|
|
907
959
|
as an installable gem for yri support (see #3).
|
|
908
960
|
|
|
@@ -1144,7 +1196,7 @@ Default rake task is now `rake yard`
|
|
|
1144
1196
|
Not a big change, but anyone using the default "rake yardoc" task should
|
|
1145
1197
|
update their scripts:
|
|
1146
1198
|
|
|
1147
|
-
[
|
|
1199
|
+
[https://github.com/lsegal/yard/commit/ad38a68dd73898b06bd5d0a1912b7d815878fae0](https://github.com/lsegal/yard/commit/ad38a68dd73898b06bd5d0a1912b7d815878fae0)
|
|
1148
1200
|
|
|
1149
1201
|
|
|
1150
1202
|
What's New in 0.2.3.x?
|
|
@@ -1204,7 +1256,7 @@ that is actually being employed. Here's an example:
|
|
|
1204
1256
|
# @overload def to_html(html, autolink = true)
|
|
1205
1257
|
# This docstring describes the specific overload only.
|
|
1206
1258
|
# @param [String] html the HTML
|
|
1207
|
-
# @param [Boolean] autolink whether or not to
|
|
1259
|
+
# @param [Boolean] autolink whether or not to automatically link
|
|
1208
1260
|
# URL references
|
|
1209
1261
|
# @overload def to_html(html, opts = {})
|
|
1210
1262
|
# @param [String] html the HTML
|
data/lib/yard/autoload.rb
CHANGED
|
@@ -69,6 +69,16 @@ module YARD
|
|
|
69
69
|
autoload :MethodHandler, __p('handlers/common/method_handler')
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
+
# RBS type signature handlers
|
|
73
|
+
module RBS
|
|
74
|
+
autoload :Base, __p('handlers/rbs/base')
|
|
75
|
+
autoload :AttributeHandler, __p('handlers/rbs/attribute_handler')
|
|
76
|
+
autoload :ConstantHandler, __p('handlers/rbs/constant_handler')
|
|
77
|
+
autoload :MethodHandler, __p('handlers/rbs/method_handler')
|
|
78
|
+
autoload :MixinHandler, __p('handlers/rbs/mixin_handler')
|
|
79
|
+
autoload :NamespaceHandler, __p('handlers/rbs/namespace_handler')
|
|
80
|
+
end
|
|
81
|
+
|
|
72
82
|
# CRuby Handlers
|
|
73
83
|
# @since 0.8.0
|
|
74
84
|
module C
|
|
@@ -170,7 +180,6 @@ module YARD
|
|
|
170
180
|
|
|
171
181
|
module Ruby # Ruby parsing components.
|
|
172
182
|
module Legacy # Handles Ruby parsing in Ruby 1.8.
|
|
173
|
-
autoload :RipperParser, __p('parser/ruby/legacy/ruby_parser')
|
|
174
183
|
autoload :RubyParser, __p('parser/ruby/legacy/ruby_parser')
|
|
175
184
|
autoload :RubyToken, __p('parser/ruby/legacy/ruby_lex')
|
|
176
185
|
autoload :Statement, __p('parser/ruby/legacy/statement')
|
|
@@ -180,9 +189,16 @@ module YARD
|
|
|
180
189
|
|
|
181
190
|
autoload :AstNode, __p('parser/ruby/ast_node')
|
|
182
191
|
autoload :RubyParser, __p('parser/ruby/ruby_parser')
|
|
192
|
+
autoload :RipperParser, __p('parser/ruby/ruby_parser')
|
|
183
193
|
autoload :TokenResolver, __p('parser/ruby/token_resolver')
|
|
184
194
|
end
|
|
185
195
|
|
|
196
|
+
# RBS type signature parser
|
|
197
|
+
module RBS
|
|
198
|
+
autoload :RbsParser, __p('parser/rbs/rbs_parser')
|
|
199
|
+
autoload :Statement, __p('parser/rbs/statement')
|
|
200
|
+
end
|
|
201
|
+
|
|
186
202
|
autoload :Base, __p('parser/base')
|
|
187
203
|
autoload :ParserSyntaxError, __p('parser/source_parser')
|
|
188
204
|
autoload :SourceParser, __p('parser/source_parser')
|
|
@@ -236,6 +252,7 @@ module YARD
|
|
|
236
252
|
autoload :FinishRequest, __p('server/adapter')
|
|
237
253
|
autoload :LibraryVersion, __p('server/library_version')
|
|
238
254
|
autoload :NotFoundError, __p('server/adapter')
|
|
255
|
+
autoload :HTTPUtils, __p('server/http_utils')
|
|
239
256
|
autoload :RackAdapter, __p('server/rack_adapter')
|
|
240
257
|
autoload :RackMiddleware, __p('server/rack_adapter')
|
|
241
258
|
autoload :Router, __p('server/router')
|
|
@@ -270,6 +287,7 @@ module YARD
|
|
|
270
287
|
module Templates
|
|
271
288
|
module Helpers # Namespace for template helpers
|
|
272
289
|
module Markup # Namespace for markup providers
|
|
290
|
+
autoload :HybridMarkdown, __p('templates/helpers/markup/hybrid_markdown')
|
|
273
291
|
autoload :RDocMarkup, __p('templates/helpers/markup/rdoc_markup')
|
|
274
292
|
autoload :RDocMarkdown, __p('templates/helpers/markup/rdoc_markdown')
|
|
275
293
|
end
|
|
@@ -297,6 +315,7 @@ module YARD
|
|
|
297
315
|
autoload :DocstringParser, __p('docstring_parser')
|
|
298
316
|
autoload :GemIndex, __p('gem_index')
|
|
299
317
|
autoload :Logger, __p('logging')
|
|
318
|
+
autoload :OpenStruct, __p('open_struct')
|
|
300
319
|
autoload :Options, __p('options')
|
|
301
320
|
autoload :Registry, __p('registry')
|
|
302
321
|
autoload :RegistryResolver, __p('registry_resolver')
|
data/lib/yard/cli/command.rb
CHANGED
data/lib/yard/cli/diff.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
require 'tmpdir'
|
|
3
3
|
require 'fileutils'
|
|
4
4
|
require 'open-uri'
|
|
5
|
+
require 'open3'
|
|
5
6
|
|
|
6
7
|
module YARD
|
|
7
8
|
module CLI
|
|
@@ -108,7 +109,11 @@ module YARD
|
|
|
108
109
|
FileUtils.mkdir_p(tmpdir)
|
|
109
110
|
FileUtils.cp_r('.', tmpdir)
|
|
110
111
|
Dir.chdir(tmpdir)
|
|
111
|
-
|
|
112
|
+
out, status = Open3.capture2e('git', 'reset', '--hard', commit)
|
|
113
|
+
log.info("git says: " + out.chomp)
|
|
114
|
+
unless status.success?
|
|
115
|
+
raise "git reset --hard #{commit.inspect} failed with exit status #{status.exitstatus}: #{out}"
|
|
116
|
+
end
|
|
112
117
|
generate_yardoc(tmpdir)
|
|
113
118
|
ensure
|
|
114
119
|
Dir.chdir(@old_path)
|
|
@@ -158,7 +163,7 @@ module YARD
|
|
|
158
163
|
end
|
|
159
164
|
|
|
160
165
|
# Remote gemfile from rubygems.org
|
|
161
|
-
url = "
|
|
166
|
+
url = "https://rubygems.org/downloads/#{gemfile}"
|
|
162
167
|
log.info "Searching for remote gem file #{url}"
|
|
163
168
|
begin
|
|
164
169
|
# Note: In Ruby 2.4.x, URI.open is a private method. After
|
data/lib/yard/cli/yardoc.rb
CHANGED
|
@@ -334,7 +334,7 @@ module YARD
|
|
|
334
334
|
private
|
|
335
335
|
|
|
336
336
|
# Generates output for objects
|
|
337
|
-
# @param [Hash, nil] checksums if supplied, a list of
|
|
337
|
+
# @param [Hash, nil] checksums if supplied, a list of checksums for files.
|
|
338
338
|
# @return [void]
|
|
339
339
|
# @since 0.5.1
|
|
340
340
|
def run_generate(checksums)
|
|
@@ -228,7 +228,7 @@ module YARD
|
|
|
228
228
|
# @example Create class Z inside namespace X::Y
|
|
229
229
|
# CodeObjects::Base.new(P("X::Y"), :Z) # or
|
|
230
230
|
# CodeObjects::Base.new(Registry.root, "X::Y")
|
|
231
|
-
# @param [NamespaceObject] namespace the namespace the object belongs in,
|
|
231
|
+
# @param [NamespaceObject, :root, nil] namespace the namespace the object belongs in,
|
|
232
232
|
# {Registry.root} or :root should be provided if it is associated with
|
|
233
233
|
# the top level namespace.
|
|
234
234
|
# @param [Symbol, String] name the name (or complex path) of the object.
|
|
@@ -303,6 +303,7 @@ module YARD
|
|
|
303
303
|
# definitions with docstrings first.
|
|
304
304
|
#
|
|
305
305
|
# @return [String] a filename
|
|
306
|
+
# @return [nil] if there is no file associated with the object
|
|
306
307
|
def file
|
|
307
308
|
@files.first ? @files.first[0] : nil
|
|
308
309
|
end
|
|
@@ -434,7 +435,10 @@ module YARD
|
|
|
434
435
|
#
|
|
435
436
|
# @return [Symbol] the type of code object this represents
|
|
436
437
|
def type
|
|
437
|
-
self.class.name.split('::').last
|
|
438
|
+
obj_name = self.class.name.split('::').last
|
|
439
|
+
obj_name.gsub!(/Object$/, '')
|
|
440
|
+
obj_name.downcase!
|
|
441
|
+
obj_name.to_sym
|
|
438
442
|
end
|
|
439
443
|
|
|
440
444
|
# Represents the unique path of the object. The default implementation
|
|
@@ -201,7 +201,7 @@ module YARD
|
|
|
201
201
|
|
|
202
202
|
private
|
|
203
203
|
|
|
204
|
-
# @note this method fixes a bug in 1.9.2:
|
|
204
|
+
# @note this method fixes a bug in 1.9.2: https://gist.github.com/437136
|
|
205
205
|
def to_ary; nil end
|
|
206
206
|
|
|
207
207
|
# Attempts to find the object that this unresolved object
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
require 'ostruct'
|
|
3
2
|
|
|
4
3
|
module YARD
|
|
5
4
|
# Parses text and creates a {Docstring} object to represent documentation
|
|
@@ -8,7 +7,7 @@ module YARD
|
|
|
8
7
|
#
|
|
9
8
|
# == Subclassing Notes
|
|
10
9
|
#
|
|
11
|
-
# The DocstringParser can be subclassed and
|
|
10
|
+
# The DocstringParser can be subclassed and substituted during parsing by
|
|
12
11
|
# setting the {Docstring.default_parser} attribute with the name of the
|
|
13
12
|
# subclass. This allows developers to change the way docstrings are
|
|
14
13
|
# parsed, allowing for completely different docstring syntaxes.
|
data/lib/yard/handlers/base.rb
CHANGED
|
@@ -462,6 +462,18 @@ module YARD
|
|
|
462
462
|
end
|
|
463
463
|
end
|
|
464
464
|
|
|
465
|
+
if docstring.is_a?(String)
|
|
466
|
+
if (m = docstring.match(/^\s*@!?visibility\s+(public|private|protected)\b/m))
|
|
467
|
+
vis_sym = m[1].to_sym
|
|
468
|
+
|
|
469
|
+
if object.nil?
|
|
470
|
+
globals.visibility_origin = :directive
|
|
471
|
+
elsif object.is_a?(CodeObjects::MethodObject)
|
|
472
|
+
object.visibility = vis_sym
|
|
473
|
+
end
|
|
474
|
+
end
|
|
475
|
+
end
|
|
476
|
+
|
|
465
477
|
register_transitive_tags(object)
|
|
466
478
|
end
|
|
467
479
|
|
|
@@ -511,7 +523,17 @@ module YARD
|
|
|
511
523
|
def register_visibility(object, visibility = self.visibility)
|
|
512
524
|
return unless object.respond_to?(:visibility=)
|
|
513
525
|
return if object.is_a?(NamespaceObject)
|
|
514
|
-
|
|
526
|
+
|
|
527
|
+
if object.is_a?(CodeObjects::MethodObject)
|
|
528
|
+
origin = globals.visibility_origin
|
|
529
|
+
if origin == :keyword
|
|
530
|
+
object.visibility = visibility if object.scope == scope
|
|
531
|
+
else
|
|
532
|
+
object.visibility = visibility
|
|
533
|
+
end
|
|
534
|
+
else
|
|
535
|
+
object.visibility = visibility
|
|
536
|
+
end
|
|
515
537
|
end
|
|
516
538
|
|
|
517
539
|
# Registers the same method information on the module function, if
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
require 'ostruct'
|
|
3
2
|
|
|
4
3
|
module YARD
|
|
5
4
|
module Handlers
|
|
@@ -36,6 +35,7 @@ module YARD
|
|
|
36
35
|
register_handler_namespace :ruby, Ruby
|
|
37
36
|
register_handler_namespace :ruby18, Ruby::Legacy
|
|
38
37
|
register_handler_namespace :c, C
|
|
38
|
+
register_handler_namespace :rbs, RBS
|
|
39
39
|
|
|
40
40
|
# @return [String] the filename
|
|
41
41
|
attr_accessor :file
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Handles RBS attr_reader, attr_writer, and attr_accessor declarations.
|
|
3
|
+
#
|
|
4
|
+
# Registers one or two {YARD::CodeObjects::MethodObject} instances (reader
|
|
5
|
+
# and/or writer) with @return / @param tags derived from the RBS type.
|
|
6
|
+
class YARD::Handlers::RBS::AttributeHandler < YARD::Handlers::RBS::Base
|
|
7
|
+
handles :attr_reader, :attr_writer, :attr_accessor
|
|
8
|
+
|
|
9
|
+
process do
|
|
10
|
+
attr_name = statement.name
|
|
11
|
+
rbs_type = statement.attr_rbs_type
|
|
12
|
+
yard_types = rbs_type ? YARD::Handlers::RBS::MethodHandler.rbs_type_to_yard_types(rbs_type) : nil
|
|
13
|
+
mscope = statement.visibility == :class ? :class : :instance
|
|
14
|
+
|
|
15
|
+
case statement.type
|
|
16
|
+
when :attr_reader
|
|
17
|
+
register_reader(attr_name, yard_types, mscope)
|
|
18
|
+
register_existing_attribute_method(attr_name, "#{attr_name}=", :write, mscope)
|
|
19
|
+
when :attr_writer
|
|
20
|
+
register_existing_attribute_method(attr_name, attr_name, :read, mscope)
|
|
21
|
+
register_writer(attr_name, yard_types, mscope)
|
|
22
|
+
when :attr_accessor
|
|
23
|
+
register_reader(attr_name, yard_types, mscope)
|
|
24
|
+
register_writer(attr_name, yard_types, mscope)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def register_reader(name, types, scope)
|
|
31
|
+
obj = MethodObject.new(namespace, name, scope)
|
|
32
|
+
obj.source ||= "def #{name}\n @#{name}\nend"
|
|
33
|
+
obj.signature ||= "def #{name}"
|
|
34
|
+
obj = register(obj)
|
|
35
|
+
obj.docstring = "Returns the value of attribute #{name}." if obj.docstring.blank?(false)
|
|
36
|
+
apply_tag_types(obj, :return, types)
|
|
37
|
+
namespace.attributes[obj.scope][name] ||= SymbolHash[:read => nil, :write => nil]
|
|
38
|
+
namespace.attributes[obj.scope][name][:read] = obj
|
|
39
|
+
obj
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def register_writer(name, types, scope)
|
|
43
|
+
obj = MethodObject.new(namespace, "#{name}=", scope)
|
|
44
|
+
obj.parameters = [['value', nil]]
|
|
45
|
+
obj.source ||= "def #{name}=(value)\n @#{name} = value\nend"
|
|
46
|
+
obj.signature ||= "def #{name}=(value)"
|
|
47
|
+
obj = register(obj)
|
|
48
|
+
obj.docstring = "Sets the attribute #{name}\n@param value the value to set the attribute #{name} to." if obj.docstring.blank?(false)
|
|
49
|
+
apply_tag_types(obj, :param, types, "value")
|
|
50
|
+
namespace.attributes[obj.scope][name] ||= SymbolHash[:read => nil, :write => nil]
|
|
51
|
+
namespace.attributes[obj.scope][name][:write] = obj
|
|
52
|
+
obj
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def register_existing_attribute_method(attr_name, meth_name, type, scope)
|
|
56
|
+
namespace.attributes[scope][attr_name] ||= SymbolHash[:read => nil, :write => nil]
|
|
57
|
+
return if namespace.attributes[scope][attr_name][type]
|
|
58
|
+
|
|
59
|
+
obj = namespace.children.find do |other|
|
|
60
|
+
other.name == meth_name.to_sym && other.scope == scope
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
namespace.attributes[scope][attr_name][type] = obj if obj
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def apply_tag_types(obj, tag_name, types, tag_param_name = nil)
|
|
67
|
+
return unless types
|
|
68
|
+
|
|
69
|
+
tag = obj.tags(tag_name).find do |existing_tag|
|
|
70
|
+
existing_tag.name == tag_param_name
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
if tag
|
|
74
|
+
tag.types ||= types
|
|
75
|
+
else
|
|
76
|
+
obj.add_tag YARD::Tags::Tag.new(tag_name, '', types, tag_param_name)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module YARD
|
|
3
|
+
module Handlers
|
|
4
|
+
# Handlers for RBS (Ruby type signature) files.
|
|
5
|
+
module RBS
|
|
6
|
+
# Base class for all RBS handlers.
|
|
7
|
+
# Handlers match on the {Parser::RBS::Statement#type} symbol of the
|
|
8
|
+
# current statement and process it to create or annotate code objects.
|
|
9
|
+
class Base < Handlers::Base
|
|
10
|
+
# @return [Boolean] whether this handler matches the given statement
|
|
11
|
+
def self.handles?(statement, _processor)
|
|
12
|
+
handlers.any? do |matcher|
|
|
13
|
+
case matcher
|
|
14
|
+
when Symbol
|
|
15
|
+
statement.type == matcher
|
|
16
|
+
when String
|
|
17
|
+
statement.type.to_s == matcher
|
|
18
|
+
when Regexp
|
|
19
|
+
(statement.source || '') =~ matcher
|
|
20
|
+
else
|
|
21
|
+
false
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Recurse into the body of a namespace statement.
|
|
27
|
+
# @param opts [Hash] state overrides
|
|
28
|
+
# @see #push_state
|
|
29
|
+
def parse_block(opts = {})
|
|
30
|
+
return if statement.block.nil? || statement.block.empty?
|
|
31
|
+
push_state(opts) do
|
|
32
|
+
parser.process(statement.block)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Handles RBS constant declarations: `Name: Type`
|
|
3
|
+
class YARD::Handlers::RBS::ConstantHandler < YARD::Handlers::RBS::Base
|
|
4
|
+
handles :constant
|
|
5
|
+
|
|
6
|
+
process do
|
|
7
|
+
obj = register ConstantObject.new(namespace, statement.name)
|
|
8
|
+
if statement.attr_rbs_type && !obj.has_tag?(:return)
|
|
9
|
+
obj.add_tag YARD::Tags::Tag.new(:return, '', rbs_types(statement.attr_rbs_type))
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def rbs_types(type_str)
|
|
16
|
+
YARD::Handlers::RBS::MethodHandler.rbs_type_to_yard_types(type_str)
|
|
17
|
+
end
|
|
18
|
+
end
|