Class: YARD::Tags::Directive Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/tags/directives.rb

Overview

This class is abstract.

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.

See Also:

Since:

  • 0.8.0

Instance Attribute Summary (collapse)

Parser callbacks (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Directive) initialize(tag, parser)

Returns a new instance of Directive

Since:

  • 0.8.0



54
55
56
57
58
# File 'lib/yard/tags/directives.rb', line 54

def initialize(tag, parser)
  self.tag = tag
  self.parser = parser
  self.expanded_text = nil
end

Instance Attribute Details

- (String?) expanded_text

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.

Since:

  • 0.8.0



33
34
35
# File 'lib/yard/tags/directives.rb', line 33

def expanded_text
  @expanded_text
end

- (Handlers::Base?) handler (readonly)

Returns the handler object the docstring parser might be attached to. May be nil. Only available when parsing through Parser::SourceParser.

Since:

  • 0.8.0



48
# File 'lib/yard/tags/directives.rb', line 48

def handler; parser.handler end

- (CodeObjects::Base?) object (readonly)

Returns the object the parent docstring is attached to. May be nil.

Since:

  • 0.8.0



42
# File 'lib/yard/tags/directives.rb', line 42

def object; parser.object end

- (DocstringParser) parser (protected)

Returns the parser that is parsing all tag information out of the docstring

Since:

  • 0.8.0



37
38
39
# File 'lib/yard/tags/directives.rb', line 37

def parser
  @parser
end

- (Tag) tag

Returns the meta-data tag containing data input to the directive

Since:

  • 0.8.0



24
25
26
# File 'lib/yard/tags/directives.rb', line 24

def tag
  @tag
end

Instance Method Details

- (void) after_parse

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.

Since:

  • 0.8.0



73
# File 'lib/yard/tags/directives.rb', line 73

def after_parse; end

- (void) call

This method is abstract.

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.

Raises:

  • (NotImplementedError)

Since:

  • 0.8.0



68
# File 'lib/yard/tags/directives.rb', line 68

def call; raise NotImplementedError end