123456789_123456789_123456789_123456789_123456789_

Class: YARD::Handlers::Ruby::MethodHandler

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

Overview

Handles a method definition

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

.handles?,
.meta_type

Matcher for handling a node with a specific meta-type.

.method_call

Matcher for handling any type of method call.

::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::Handlers::Common::MethodHandler - Included

Base - Inherited

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

Instance Method Details

#format_args

[ GitHub ]

  
# File 'lib/yard/handlers/ruby/method_handler.rb', line 69

def format_args
  return [] unless args = statement.parameters

  params = []

  if args.unnamed_required_params
    params += args.unnamed_required_params.map {|a| [a.source, nil] }
  end

  if args.unnamed_optional_params
    params += args.unnamed_optional_params.map do |a|
      [a[0].source, a[1].source]
    end
  end

  params << ['*' + args.splat_param.source, nil] if args.splat_param

  if args.unnamed_end_params
    params += args.unnamed_end_params.map {|a| [a.source, nil] }
  end

  if args.named_params
    params += args.named_params.map do |a|
      [a[0].source, a[1] ? a[1].source : nil]
    end
  end

  if args.double_splat_param
    params << ['**' + args.double_splat_param.source, nil]
  end

  params << ['&' + args.block_param.source, nil] if args.block_param && !args.args_forward

  params
end

#processvoid

This method returns an undefined value.

Main processing callback

[ GitHub ]

  
# File 'lib/yard/handlers/ruby/method_handler.rb', line 8

process do
  meth = statement.method_name(true).to_s
  args = format_args
  blk = statement.block
  nobj = namespace
  mscope = scope
  if statement.type == :defs
    if statement[0][0].type == :ident
      raise YARD::Parser::UndocumentableError, 'method defined on object instance'
    end
    nobj = P(namespace, statement[0].source) if statement[0][0].type == :const
    mscope = :class
  end

  nobj = P(namespace, nobj.value) while nobj.type == :constant
  obj = register MethodObject.new(nobj, meth, mscope) do |o|
    o.explicit = true
    o.parameters = args
  end

  # delete any aliases referencing old method
  nobj.aliases.each do |aobj, name|
    next unless name == obj.name
    nobj.aliases.delete(aobj)
  end if nobj.is_a?(NamespaceObject)

  if obj.constructor?
    unless obj.has_tag?(:return)
      obj.add_tag(YARD::Tags::Tag.new(:return,
        "a new instance of #{namespace.name}", namespace.name.to_s))
    end
  elsif mscope == :class && obj.docstring.blank? && %w(inherited included
      extended method_added method_removed method_undefined).include?(meth)
    obj.add_tag(YARD::Tags::Tag.new(:private, nil))
  elsif meth.to_s =~ /\?$/
    add_predicate_return_tag(obj)
  end

  if obj.has_tag?(:option)
    # create the options parameter if its missing
    obj.tags(:option).each do |option|
      expected_param = option.name
      unless obj.tags(:param).find {|x| x.name == expected_param }
        new_tag = YARD::Tags::Tag.new(:param, "a customizable set of options", "Hash", expected_param)
        obj.add_tag(new_tag)
      end
    end
  end

  info = obj.attr_info
  if info
    if meth.to_s =~ /=$/ # writer
      info[:write] = obj if info[:read]
    elsif info[:write]
      info[:read] = obj
    end
  end

  parse_block(blk, :owner => obj) # mainly for yield/exceptions
end