Class: YARD::Tags::ParseDirective

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

Overview

Parses a block of code as if it were present in the source file at that location. This directive is useful if a class has dynamic meta-programmed behaviour that cannot be recognized by YARD.

You can specify the language of the code block using the types specification list. By default, the code language is “ruby”.

Examples:

Documenting dynamic module inclusion

class User
  # includes "UserMixin" and extends "UserMixin::ClassMethods"
  # using the UserMixin.included callback.
  # @!parse include UserMixin
  # @!parse extend UserMixin::ClassMethods
end

Declaring a method as an attribute

# This should really be an attribute
# @!parse attr_reader :foo
def object; @parent.object end

Parsing C code

# @!parse [c]
#   void Init_Foo() {
#     rb_define_method(rb_cFoo, "method", method, 0);
#   }

Since:

  • 0.8.0

Instance Attribute Summary collapse

Parser callbacks collapse

Constructor Details

This class inherits a constructor from YARD::Tags::Directive

Instance Attribute Details

#expanded_textString? 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.

Returns:

  • (String)

    the text to expand in the original docstring in place of this directive definition.

  • (nil)

    if no expansion should take place for this directive

Since:

  • 0.8.0

#handlerHandlers::Base? (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.

Returns:

Since:

  • 0.8.0

#objectCodeObjects::Base? (readonly) Originally defined in class Directive

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

Returns:

  • (CodeObjects::Base, nil)

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

Since:

  • 0.8.0

#parserDocstringParser (protected) Originally defined in class Directive

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

Returns:

  • (DocstringParser)

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

Since:

  • 0.8.0

#tagTag Originally defined in class Directive

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

Returns:

  • (Tag)

    the meta-data tag containing data input to the directive

Since:

  • 0.8.0

Instance Method Details

#callObject

Since:

  • 0.8.0



522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/yard/tags/directives.rb', line 522

def call
  lang = tag.types ? tag.types.first.to_sym :
    (handler ? handler.parser.parser_type : :ruby)
  if handler && lang == handler.parser.parser_type
    pclass = Parser::SourceParser.parser_types[handler.parser.parser_type]
    pobj = pclass.new(tag.text, handler.parser.file)
    pobj.parse
    handler.parser.process(pobj.enumerator)
  else # initialize a new parse chain
    src_parser = Parser::SourceParser.new(lang, handler ? handler.globals : nil)
    src_parser.file = handler.parser.file if handler
    src_parser.parse(StringIO.new(tag.text))
  end
end