Class: YARD::Tags::Directive Abstract
- Inherits:
-
Object
- Object
- YARD::Tags::Directive
- Defined in:
- lib/yard/tags/directives.rb
Overview
Subclasses should implement #call.
The base directive class. Subclass this class to create a custom directive, registering it with Library.define_directive. Directive classes are executed via the #call method, which perform all directive processing on the object.
If processing occurs within a handler, the #handler attribute is available to access more information about parsing context and state. Handlers are only available when parsing from Parser::SourceParser, not when parsing directly from DocstringParser. If the docstring is attached to an object declaration, #object will be set and available to modify the generated code object directly. Note that both of these attributes may be nil, and directives should test their existence before attempting to use them.
Direct Known Subclasses
EndGroupDirective, GroupDirective, MacroDirective, MethodDirective, ParseDirective, ScopeDirective, VisibilityDirective
Instance Attribute Summary collapse
-
#expanded_text ⇒ String?
Set this field to replace the directive definition inside of a docstring with arbitrary text.
-
#handler ⇒ Handlers::Base?
readonly
The handler object the docstring parser might be attached to.
-
#object ⇒ CodeObjects::Base?
readonly
The object the parent docstring is attached to.
-
#parser ⇒ DocstringParser
protected
The parser that is parsing all tag information out of the docstring.
-
#tag ⇒ Tag
The meta-data tag containing data input to the directive.
Parser callbacks collapse
-
#after_parse ⇒ void
Called after parsing all directives and tags in the docstring.
-
#call ⇒ void
abstract
Called when processing the directive.
- #inside_directive? ⇒ Boolean protected
Instance Method Summary collapse
-
#initialize(tag, parser) ⇒ Directive
constructor
A new instance of Directive.
Constructor Details
#initialize(tag, parser) ⇒ Directive
Returns a new instance of Directive.
55 56 57 58 59 |
# File 'lib/yard/tags/directives.rb', line 55 def initialize(tag, parser) self.tag = tag self.parser = parser self. = nil end |
Instance Attribute Details
#expanded_text ⇒ String?
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.
34 35 36 |
# File 'lib/yard/tags/directives.rb', line 34 def @expanded_text end |
#handler ⇒ Handlers::Base? (readonly)
Returns the handler object the docstring parser might be attached to. May be nil. Only available when parsing through Parser::SourceParser.
49 |
# File 'lib/yard/tags/directives.rb', line 49 def handler; parser.handler end |
#object ⇒ CodeObjects::Base? (readonly)
Returns the object the parent docstring is attached to. May be nil.
43 |
# File 'lib/yard/tags/directives.rb', line 43 def object; parser.object end |
#parser ⇒ DocstringParser (protected)
Returns the parser that is parsing all tag information out of the docstring.
38 39 40 |
# File 'lib/yard/tags/directives.rb', line 38 def parser @parser end |
#tag ⇒ Tag
Returns the meta-data tag containing data input to the directive.
25 26 27 |
# File 'lib/yard/tags/directives.rb', line 25 def tag @tag end |
Instance Method Details
#after_parse ⇒ void
This method returns an undefined value.
Called after parsing all directives and tags in the docstring. Used to perform any cleanup after all directives perform their main task.
74 |
# File 'lib/yard/tags/directives.rb', line 74 def after_parse; end |
#call ⇒ void
implement this method to perform all data processing for the directive.
This method returns an undefined value.
Called when processing the directive. Subclasses should implement this method to perform all functionality of the directive.
69 |
# File 'lib/yard/tags/directives.rb', line 69 def call; raise NotImplementedError end |
#inside_directive? ⇒ Boolean (protected)
80 81 82 83 |
# File 'lib/yard/tags/directives.rb', line 80 def inside_directive? return true if parser.state.inside_directive parser.directives.any? { |d| d.is_a?(MethodDirective) && d.tag.text.empty? } end |