class YARD::Tags::AttributeDirective
@since 0.7.0
@see tag:!method
# @return [String] the name of the user
# @!attribute name
@example Defining a simple readwrite attribute
# @return [Fixnum] the size of the list
# @!attribute [r] count
@example Defining a simple readonly attribute
docstring text.
no indented block, the entire docstring is used as the new attribute’s
the attribute’s docstring text. If an +@!attribute+ directive is seen with
@note For backwards compatibility support, you do not need to indent
documentation to the attribute declaration itself.
is declared dynamically via meta-programming). In all other cases, add
declaration for the attribute in any source files (i.e., the attribute
@note This directive should only be used if there is no explicit attr_*
To define a regular method, see {tag:!method}
if it is, that source code will be used as the method’s source.
containing this directive does not need to be attached to any source, but
A readwrite attribute is the default, if no type is specified. The comment
“rw”, the attribute is made readonly, writeonly or readwrite respectively.
attribute’s docstring. If the type specifier is supplied with “r”, “w”, or
Defines an attribute with a given name, using indented block data as the
def after_parse
def after_parse return unless handler use_indented_text create_attribute_data(create_object) end
def create_attribute_data(object)
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
def method_name
def method_name name = sanitized_tag_signature || handler.call_params.first name += '=' unless readable? name end
def method_signature
def method_signature if readable? "def #{method_name}" else "def #{method_name}(value)" end end
def readable?
def readable? !tag.types || tag.types.join =~ /(?!w)r/ end
def writable?
def writable? !tag.types || tag.types.join.include?('w') end