123456789_123456789_123456789_123456789_123456789_

Class: YARD::Handlers::Ruby::Legacy::AttributeHandler

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

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

::YARD::Parser::Ruby::Legacy::RubyToken - Included

EXPR_ARG, EXPR_BEG, EXPR_CLASS, EXPR_DOT, EXPR_END, EXPR_FNAME, EXPR_MID, NEWLINE_TOKEN, TkReading2Token, TkSymbol2Token, TokenDefinitions

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?

This class is implemented by ::YARD::Handlers::Ruby::Base and Base.

.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

#call_params, #caller_method,
#parse_block

Parses a statement's block with a set of state values.

#extract_method_details

Extracts method information for macro expansion only.

#tokval

The string value of a token.

#tokval_list

Returns a list of symbols or string values from a statement.

::YARD::Parser::Ruby::Legacy::RubyToken - Included

::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

#processvoid

This method returns an undefined value.

Main processing callback

[ GitHub ]

  
# File 'lib/yard/handlers/ruby/legacy/attribute_handler.rb', line 7

process do
  begin
    attr_type   = statement.tokens.first.text.to_sym
    symbols     = tokval_list statement.tokens[2..-1], :attr, TkTRUE, TkFALSE
    read = true
    write = false
  rescue SyntaxError
    raise YARD::Parser::UndocumentableError, attr_type
  end

  # Change read/write based on attr_reader/writer/accessor
  case attr_type
  when :attr
    # In the case of 'attr', the second parameter (if given) isn't a symbol.
    write = symbols.pop if symbols.size == 2
  when :attr_accessor
    write = true
  when :attr_reader
    # change nothing
  when :attr_writer
    read = false
    write = true
  end

  # Add all attributes
  symbols.each do |name|
    namespace.attributes[scope][name] = SymbolHash[:read => nil, :write => nil]

    # Show their methods as well
    {:read => name, :write => "#{name}="}.each do |type, meth|
      if type == :read ? read : write
        o = MethodObject.new(namespace, meth, scope)
        if type == :write
          o.parameters = [['value', nil]]
          src = "def #{meth}(value)"
          full_src = "#{src}\n  @#{name} = value\nend"
          doc = "Sets the attribute #{name}\n@param value the value to set the attribute #{name} to."
        else
          src = "def #{meth}"
          full_src = "#{src}\n  @#{name}\nend"
          doc = "Returns the value of attribute #{name}"
        end
        o.source ||= full_src
        o.signature ||= src
        register(o)
        o.docstring = doc if o.docstring.blank?(false)

        # Register the object explicitly
        namespace.attributes[scope][name][type] = o
      else
        obj = namespace.children.find {|other| other.name == meth.to_sym && other.scope == scope }

        # register an existing method as attribute
        namespace.attributes[scope][name][type] = obj if obj
      end
    end
  end
end