Class: YARD::Tags::MethodDirective
- Inherits:
-
Directive
- Object
- Directive
- YARD::Tags::MethodDirective
- Defined in:
- lib/yard/tags/directives.rb
Overview
For backwards compatibility support, you do not need to indent the method’s docstring text. If a @!method directive is seen with no indented block, the entire docstring is used as the new method’s docstring text.
Defines a method object with a given method signature, using indented block data as the method's docstring. The signature is similar to the @overload tag. The comment containing this directive does not need to be attached to any source, but if it is, that source code will be used as the method's source.
To define an attribute method, see @!attribute
Direct Known Subclasses
Constant Summary
- SCOPE_MATCH =
/\A\s*self\s*\.\s*/
Instance Attribute Summary (collapse)
-
- (String?) expanded_text
inherited
from Directive
Set this field to replace the directive definition inside of a docstring with arbitrary text.
-
- (Handlers::Base?) handler
inherited
from Directive
readonly
The handler object the docstring parser might be attached to.
-
- (CodeObjects::Base?) object
inherited
from Directive
readonly
The object the parent docstring is attached to.
-
- (DocstringParser) parser
inherited
from Directive
protected
The parser that is parsing all tag information out of the docstring.
-
- (Tag) tag
inherited
from Directive
The meta-data tag containing data input to the directive.
Parser callbacks (collapse)
- - (Object) after_parse
- - (Object) call
- - (Object) create_object protected
- - (Object) method_name protected
- - (Object) method_signature protected
- - (Object) sanitized_tag_signature protected
- - (Object) use_indented_text protected
Constructor Details
This class inherits a constructor from YARD::Tags::Directive
Instance Attribute Details
- (String?) expanded_text Originally defined in class Directive
Set this field to replace the directive definition inside of a docstring with arbitrary text. For instance, the MacroDirective uses this field to expand its macro data in place of the call to a @!macro.
- (Handlers::Base?) handler (readonly) Originally defined in class Directive
Returns the handler object the docstring parser might be attached to. May be nil. Only available when parsing through Parser::SourceParser.
- (CodeObjects::Base?) object (readonly) Originally defined in class Directive
Returns the object the parent docstring is attached to. May be nil.
- (DocstringParser) parser (protected) Originally defined in class Directive
Returns the parser that is parsing all tag information out of the docstring
Instance Method Details
- (Object) after_parse
356 357 358 359 360 |
# File 'lib/yard/tags/directives.rb', line 356 def after_parse return unless handler use_indented_text create_object end |
- (Object) call
354 |
# File 'lib/yard/tags/directives.rb', line 354 def call; end |
- (Object) create_object (protected)
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/yard/tags/directives.rb', line 396 def create_object name = method_name scope = parser.state.scope || handler.scope visibility = parser.state.visibility || handler.visibility ns = CodeObjects::NamespaceObject === object ? object : handler.namespace obj = CodeObjects::MethodObject.new(ns, name, scope) handler.register_file_info(obj) handler.register_source(obj) handler.register_visibility(obj, visibility) handler.register_group(obj) obj.signature = method_signature obj.parameters = OverloadTag.new(:overload, method_signature).parameters obj.docstring = Docstring.new!(parser.text, parser., obj, parser.raw_text, parser.reference) handler.register_module_function(obj) obj end |
- (Object) method_name (protected)
364 365 366 367 368 369 370 371 |
# File 'lib/yard/tags/directives.rb', line 364 def method_name sig = sanitized_tag_signature if sig && sig =~ /^#{CodeObjects::METHODNAMEMATCH}(\s|\(|$)/ sig[/\A\s*([^\(; \t]+)/, 1] else handler.call_params.first end end |
- (Object) method_signature (protected)
373 374 375 |
# File 'lib/yard/tags/directives.rb', line 373 def method_signature "def #{sanitized_tag_signature || method_name}" end |
- (Object) sanitized_tag_signature (protected)
377 378 379 380 381 382 383 384 |
# File 'lib/yard/tags/directives.rb', line 377 def sanitized_tag_signature if tag.name && tag.name =~ SCOPE_MATCH parser.state.scope = :class $' else tag.name end end |
- (Object) use_indented_text (protected)
386 387 388 389 390 391 392 393 394 |
# File 'lib/yard/tags/directives.rb', line 386 def use_indented_text return if tag.text.empty? handler = parser.handler object = parser.object self.parser = parser.class.new(parser.library) parser.state.inside_directive = true parser.parse(tag.text, object, handler) parser.state.inside_directive = false end |