class YARD::Tags::Directive

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.

@abstract Subclasses should implement {#call}. @see Library.define_directive @since 0.8.0

Attributes

expanded_text[RW]

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+.

@return [String] the text to expand in the original docstring in place

of this directive definition.

@return [nil] if no expansion should take place for this directive

parser[RW]

@return [DocstringParser] the parser that is parsing all tag

information out of the docstring
tag[RW]

@return [Tag] the meta-data tag containing data input to the directive

Public Class Methods

new(tag, parser) click to toggle source

@param [Tag] tag the meta-data tag containing all input to the docstring @param [DocstringParser] parser the docstring parser object

# File lib/yard/tags/directives.rb, line 55
def initialize(tag, parser)
  self.tag = tag
  self.parser = parser
  self.expanded_text = nil
end

Public Instance Methods

after_parse() click to toggle source

Called after parsing all directives and tags in the docstring. Used to perform any cleanup after all directives perform their main task. @return [void]

# File lib/yard/tags/directives.rb, line 74
def after_parse; end
call() click to toggle source

Called when processing the directive. Subclasses should implement this method to perform all functionality of the directive.

@abstract implement this method to perform all data processing for

the directive.

@return [void]

# File lib/yard/tags/directives.rb, line 69
def call; raise NotImplementedError end
handler() click to toggle source

@!attribute [r] handler @return [Handlers::Base, nil] the handler object the docstring parser

might be attached to. May be nil. Only available when parsing
through {Parser::SourceParser}.
# File lib/yard/tags/directives.rb, line 49
def handler; parser.handler end
object() click to toggle source

@!attribute [r] object @return [CodeObjects::Base, nil] the object the parent docstring is

attached to. May be nil.
# File lib/yard/tags/directives.rb, line 43
def object; parser.object end