Class: YARD::Tags::AttributeDirective

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

Overview

Note:

For backwards compatibility support, you do not need to indent the attribute’s docstring text. If an @!attribute directive is seen with no indented block, the entire docstring is used as the new attribute’s docstring text.

Defines an attribute with a given name, using indented block data as the attribute's docstring. If the type specifier is supplied with "r", "w", or "rw", the attribute is made readonly, writeonly or readwrite respectively. A readwrite attribute is the default, if no type is specified. 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 regular method, see @!method

Examples:

Defining a simple readonly attribute

# @!attribute [r] count
#   @return [Fixnum] the size of the list

Defining a simple readwrite attribute

# @!attribute name
#   @return [String] the name of the user

See Also:

Since:

Constant Summary

Instance Attribute Summary (collapse)

Parser callbacks (collapse)

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.

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

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

Returns:

Since:

  • 0.8.0

- (CodeObjects::Base?) object (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

- (DocstringParser) parser (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

- (Tag) tag 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

- (Object) after_parse

Since:

  • 0.7.0



437
438
439
440
441
# File 'lib/yard/tags/directives.rb', line 437

def after_parse
  return unless handler
  use_indented_text
  create_attribute_data(create_object)
end

- (Object) method_name (protected)

Since:

  • 0.7.0



445
446
447
448
449
# File 'lib/yard/tags/directives.rb', line 445

def method_name
  name = sanitized_tag_signature || handler.call_params.first
  name += '=' unless readable?
  name
end

- (Object) method_signature (protected)

Since:

  • 0.7.0



451
452
453
454
455
456
457
# File 'lib/yard/tags/directives.rb', line 451

def method_signature
  if readable?
    "def #{method_name}"
  else
    "def #{method_name}(value)"
  end
end