Class: YARD::Tags::AttributeDirective
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
MethodDirective ,
Directive
|
|
Instance Chain:
self,
MethodDirective ,
Directive
|
|
Inherits: |
YARD::Tags::MethodDirective
|
Defined in: | lib/yard/tags/directives.rb |
Overview
This directive should only be used if there is no explicit attr_*
declaration for the attribute in any source files (i.e., the attribute
is declared dynamically via meta-programming). In all other cases, add
documentation to the attribute declaration itself.
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 a regular method, see @!method
Constant Summary
MethodDirective
- Inherited
Parser callbacks
- #after_parse
- #create_attribute_data(object) private
- #readable? ⇒ Boolean readonly private
- #writable? ⇒ Boolean readonly private
Class Method Summary
Instance Attribute Summary
Directive
- Inherited
#expanded_text | Set this field to replace the directive definition inside of a docstring with arbitrary text. |
#handler, #object, #tag |
Instance Method Summary
MethodDirective
- Inherited
Directive
- Inherited
#after_parse | Called after parsing all directives and tags in the docstring. |
#call | Called when processing the directive. |
Constructor Details
This class inherits a constructor from YARD::Tags::Directive
Instance Attribute Details
#readable? ⇒ Boolean
(readonly, private)
# File 'lib/yard/tags/directives.rb', line 515
def readable? !tag.types || tag.types.join =~ /(?!w)r/ end
#writable? ⇒ Boolean
(readonly, private)
# File 'lib/yard/tags/directives.rb', line 511
def writable? !tag.types || tag.types.join.include?('w') end
Instance Method Details
#after_parse
# File 'lib/yard/tags/directives.rb', line 461
def after_parse return unless handler use_indented_text create_attribute_data(create_object) end
#create_attribute_data(object) (private)
# File 'lib/yard/tags/directives.rb', line 485
def create_attribute_data(object) return unless object clean_name = object.name.to_s.sub(/=$/, '') attrs = object.namespace.attributes[object.scope] attrs[clean_name] ||= SymbolHash[:read => nil, :write => nil] attrs[clean_name][:read] = object if readable? if writable? if object.name.to_s[-1, 1] == '=' writer = object writer.parameters = [['value', nil]] else writer = CodeObjects::MethodObject.new(object.namespace, object.name.to_s + '=', object.scope) writer.signature = "def #{object.name}=(value)" writer.visibility = object.visibility writer.dynamic = object.dynamic writer.source = object.source writer.group = object.group writer.parameters = [['value', nil]] writer.docstring = object.base_docstring handler.register_file_info(writer) end attrs[clean_name][:write] = writer end end