123456789_123456789_123456789_123456789_123456789_

Class: YARD::Handlers::RBS::AttributeHandler

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: YARD::Handlers::RBS::Base
Defined in: lib/yard/handlers/rbs/attribute_handler.rb

Overview

Handles RBS attr_reader, attr_writer, and attr_accessor declarations.

Registers one or two ::YARD::CodeObjects::MethodObject instances (reader and/or writer) with @return / @param tags derived from the ::YARD::Handlers::RBS type.

Constant Summary

::YARD::CodeObjects - Included

BUILTIN_ALL, BUILTIN_CLASSES, BUILTIN_EXCEPTIONS, BUILTIN_EXCEPTIONS_HASH, BUILTIN_MODULES, CONSTANTMATCH, CONSTANTSTART, CSEP, CSEPQ, ISEP, ISEPQ, METHODMATCH, METHODNAMEMATCH, NAMESPACEMATCH, NSEP, NSEPQ, PROXY_MATCH

Class Attribute Summary

::YARD::Handlers::Base - Inherited

.namespace_only

Declares that the handler should only be called when inside a ::YARD::CodeObjects::NamespaceObject, not a method body.

.namespace_only?

Class Method Summary

Base - Inherited

::YARD::Handlers::Base - Inherited

.clear_subclasses

Clear all registered subclasses.

.handlers,
.handles

Declares the statement type which will be processed by this handler.

.handles?
.in_file

Declares that a handler should only be called when inside a filename by its basename or a regex match for the full path.

.inherited, .matches_file?, .new,
.process

Generates a process method, equivalent to +def process; ...

.subclasses

Returns all registered handler subclasses.

Instance Attribute Summary

::YARD::Handlers::Base - Inherited

#extra_state

Share state across different handlers inside of a file.

#globals

::YARD::Handlers can share state for the entire post processing stage through this attribute.

#namespace, #namespace=, #owner, #owner=, #parser, #scope, #scope=, #statement, #visibility, #visibility=

Instance Method Summary

Base - Inherited

#parse_block

Recurse into the body of a namespace statement.

::YARD::Handlers::Base - Inherited

#abort!

Aborts a handler by raising ::YARD::Handlers::HandlerAborted.

#call_params, #caller_method,
#ensure_loaded!

Ensures that a specific object has been parsed and loaded into the registry.

#parse_block

Parses the semantic "block" contained in the statement node.

#process

The main handler method called by the parser on a statement that matches the handles declaration.

#push_state

Executes a given block with specific state values for #owner, #namespace and #scope.

#register

Do some post processing on a list of code objects.

#register_docstring

Registers any docstring found for the object and expands macros.

#register_dynamic

Registers the object as dynamic if the object is defined inside a method or block (owner != namespace).

#register_ensure_loaded

Ensures that the object's namespace is loaded before attaching it to the namespace.

#register_file_info

Registers the file/line of the declaration with the object.

#register_group

Registers the object as being inside a specific group.

#register_module_function

Registers the same method information on the module function, if the object was defined as a module function.

#register_source,
#register_transitive_tags

Registers any transitive tags from the namespace on the object.

#register_visibility

Registers visibility on a method object.

Constructor Details

This class inherits a constructor from YARD::Handlers::Base

Instance Method Details

#apply_tag_types(obj, tag_name, types, tag_param_name = nil) (private)

[ GitHub ]

  
# File 'lib/yard/handlers/rbs/attribute_handler.rb', line 66

def apply_tag_types(obj, tag_name, types, tag_param_name = nil)
  return unless types

  tag = obj.tags(tag_name).find do |existing_tag|
    existing_tag.name == tag_param_name
  end

  if tag
    tag.types ||= types
  else
    obj.add_tag YARD::Tags::Tag.new(tag_name, '', types, tag_param_name)
  end
end

#register_existing_attribute_method(attr_name, meth_name, type, scope) (private)

[ GitHub ]

  
# File 'lib/yard/handlers/rbs/attribute_handler.rb', line 55

def register_existing_attribute_method(attr_name, meth_name, type, scope)
  namespace.attributes[scope][attr_name] ||= SymbolHash[:read => nil, :write => nil]
  return if namespace.attributes[scope][attr_name][type]

  obj = namespace.children.find do |other|
    other.name == meth_name.to_sym && other.scope == scope
  end

  namespace.attributes[scope][attr_name][type] = obj if obj
end

#register_reader(name, types, scope) (private)

[ GitHub ]

  
# File 'lib/yard/handlers/rbs/attribute_handler.rb', line 30

def register_reader(name, types, scope)
  obj = MethodObject.new(namespace, name, scope)
  obj.source ||= "def #{name}\n  @#{name}\nend"
  obj.signature ||= "def #{name}"
  obj = register(obj)
  obj.docstring = "Returns the value of attribute #{name}." if obj.docstring.blank?(false)
  apply_tag_types(obj, :return, types)
  namespace.attributes[obj.scope][name] ||= SymbolHash[:read => nil, :write => nil]
  namespace.attributes[obj.scope][name][:read] = obj
  obj
end

#register_writer(name, types, scope) (private)

[ GitHub ]

  
# File 'lib/yard/handlers/rbs/attribute_handler.rb', line 42

def register_writer(name, types, scope)
  obj = MethodObject.new(namespace, "#{name}=", scope)
  obj.parameters = [['value', nil]]
  obj.source ||= "def #{name}=(value)\n  @#{name} = value\nend"
  obj.signature ||= "def #{name}=(value)"
  obj = register(obj)
  obj.docstring = "Sets the attribute #{name}\n@param value the value to set the attribute #{name} to." if obj.docstring.blank?(false)
  apply_tag_types(obj, :param, types, "value")
  namespace.attributes[obj.scope][name] ||= SymbolHash[:read => nil, :write => nil]
  namespace.attributes[obj.scope][name][:write] = obj
  obj
end