123456789_123456789_123456789_123456789_123456789_

Class: YARD::Handlers::Ruby::Base Abstract

Overview

This class is abstract.

See ::YARD::Handlers::Base for subclassing information.

This is the base handler class for the new-style (1.9) ::YARD::Handlers::Ruby parser. All handlers that subclass this base class will be used when the new-style parser is used. For implementing legacy handlers, see Legacy::Base.

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

Statement Matcher Extensions

Testing for a Handler

Parsing an Inner Block

Macro Handling

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

::YARD::Parser::Ruby - Extended

s

Builds and s-expression by creating AstNode objects with the type provided by the first argument.

::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 Base and Legacy::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

::YARD::Parser::Ruby - Included

#s

Builds and s-expression by creating AstNode objects with the type provided by the first argument.

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

Class Method Details

.handles?(node) ⇒ Boolean

Returns:

  • (Boolean)

    whether or not an AstNode object should be handled by this handler

[ GitHub ]

  
# File 'lib/yard/handlers/ruby/base.rb', line 113

def handles?(node)
  handlers.any? do |a_handler|
    case a_handler
    when Symbol
      a_handler == node.type
    when String
      node.source == a_handler
    when Regexp
      node.source =~ a_handler
    when Parser::Ruby::AstNode
      a_handler == node
    when HandlesExtension
      a_handler.matches?(node)
    end
  end
end

.meta_type(type) ⇒ void

This method returns an undefined value.

Matcher for handling a node with a specific meta-type. An AstNode has a AstNode#type to define its type but can also be associated with a set of types. For instance, :if and :unless are both of the meta-type :condition.

A meta-type is any method on the AstNode class ending in "?", though you should not include the "?" suffix in your declaration. Some examples are: "condition", "call", "literal", "kw", "token", "ref".

Examples:

Handling any conditional statement (if, unless)

handles meta_type(:condition)

Parameters:

  • type (Symbol)

    the meta-type to match. A meta-type can be any method name + "?" that AstNode responds to.

[ GitHub ]

  
# File 'lib/yard/handlers/ruby/base.rb', line 105

def meta_type(type)
  TestNodeWrapper.new(type.to_s + "?")
end

.method_call(name = nil) ⇒ void

This method returns an undefined value.

Matcher for handling any type of method call. Method calls can be expressed by many AstNode types depending on the syntax with which it is called, so ::YARD allows you to use this matcher to simplify matching a method call.

Examples:

Match the "describe" method call

handles method_call(:describe)

# The following will be matched:
# describe(...)
# object.describe(...)
# describe "argument" do ... end

Parameters:

  • name (#to_s) (defaults to: nil)

    matches the method call of this name

[ GitHub ]

  
# File 'lib/yard/handlers/ruby/base.rb', line 86

def method_call(name = nil)
  MethodCallWrapper.new(name ? name.to_s : nil)
end

Instance Method Details

#call_params

[ GitHub ]

  
# File 'lib/yard/handlers/ruby/base.rb', line 144

def call_params
  return [] unless statement.respond_to?(:parameters)
  statement.parameters(false).compact.map do |param|
    if param.type == :list
      param.map {|n| n.jump(:ident, :kw, :tstring_content).source }
    else
      param.jump(:ident, :kw, :tstring_content).source
    end
  end.flatten
end

#caller_method

[ GitHub ]

  
# File 'lib/yard/handlers/ruby/base.rb', line 155

def caller_method
  if statement.call? || statement.def?
    statement.method_name(true).to_s
  elsif statement.type == :var_ref || statement.type == :vcall
    statement[0].jump(:ident, :kw).source
  end
end

#parse_block(inner_node, opts = {})

[ GitHub ]

  
# File 'lib/yard/handlers/ruby/base.rb', line 135

def parse_block(inner_node, opts = {})
  push_state(opts) do
    nodes = inner_node.type == :list ? inner_node.children : [inner_node]
    parser.process(nodes)
  end
end