Class YARD::CodeObject

Object
  |
  +--YARD::CodeObject

The documentation parser is responsible for parsing the docstring into text and saving the meta tags attached to it

Author:
Loren Segal

Attributes

attributes [R]
children [R, W]
docstring [R]
file [R]
full_source [R]
line [R]
name [R]
parent [R, W]
scope [R, W]
source [R]
type [R]
visibility [R, W]

Constructor Summary

initialize(name, type, visibility = :public, scope = :instance, parent = nil, comments = nil) {|_self| ... }

Creates a new code object with necessary information such as the object’s name (not full path), it’s type (:class, :module, :method, etc.), visibility (:public, :private, :protected) and scope (:instance or :class level). Optionally you can specify a parent object and comments too, but these can also be assigned later through the #parent= and #attach_docstring methods.

Parameters:
[String] name - the name of the object, not including its namespace (‘initialize’ for this method)
[Symbol] type - the type of object this is, including (but not limited to): :module, :class, :method, :constant
[Symbol] visibility - :public, :protected or :private depending on the visibility of the object
[Symbol] scope - :instance or :class depending on if the object is instance level or class level. Instance level objects use the ’#’ character to separate from their parent instead of ’::’
[CodeObject] parent - The parent of this object. Without a parent this object will not be registered in the Namespace
[String] comments - Comments to be parsed as a docstring for the object.
Yield Parameters:
[CodeObject] _self - the object is yielded during initialization to perform any initialization operations on it more conveniently.
Returns:
the created code object
See Also:
#attach_docstring, #parent=

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

method_missing(meth, *args, &block)

See if the method call exists in the attributes hash, and return it. Otherwise send the missing method call up the stack.

Parameters:
meth - the method name called. This method is checked in the attributes hash
args - the arguments to the call
block - an optional block for the call

Public Instance Method Summary

Object [](key)
Object []=(key, value)
Object attach_docstring(comments)
      Attaches a docstring to a code oject by parsing the comments attached to the statement .
Object attach_full_source(source)
      Manually attaches full source code for an object given the source .
Object attach_source(statement, file = nil)
      Attaches source code to a code object with an optional file location .
Object attributes
      Returns the value of attribute attributes .
Object attributes=(value)
      Sets the attribute attributes .
Object children
      Returns the value of attribute children .
Object children=(value)
      Sets the attribute children .
Object docstring
      Returns the value of attribute docstring .
Object docstring=(value)
      Sets the attribute docstring .
Object file
      Returns the value of attribute file .
Object file=(value)
      Sets the attribute file .
String format(type = :html)
      Returns a code object formatted as a given type, defaults to html. .
Object full_source
      Returns the value of attribute full_source .
Object full_source=(value)
      Sets the attribute full_source .
Boolean has_tag?(name)
      Returns true if at least one tag by the name name was declared .
Object line
      Returns the value of attribute line .
Object line=(value)
      Sets the attribute line .
Object name
      Returns the value of attribute name .
Object name=(value)
      Sets the attribute name .
Object parent
      Returns the value of attribute parent .
Object parent=(value)
      Sets the parent object and registers the object path with .
Object path
      Returns the unique path for this code object .
Object scope
      Returns the value of attribute scope .
Object scope=(value)
      Sets the attribute scope .
Object source
      Returns the value of attribute source .
Object source=(value)
      Sets the attribute source .
BaseTag tag(name)
      Convenience method to return the first tag .
Array tags(name = nil)
      Returns a list of tags specified by name or all tags if name is not specified. .
Object to_s
Object type
      Returns the value of attribute type .
Object type=(value)
      Sets the attribute type .
Object visibility
      Returns the value of attribute visibility .
Object visibility=(value)
      Sets the attribute visibility .

Public Instance Method Details

[]

public Object [](key)


[]=

public Object []=(key, value)


attach_docstring

public Object attach_docstring(comments)

Attaches a docstring to a code oject by parsing the comments attached to the statement and filling the #tags and #docstring methods with the parsed information.

Parameters:
[String, Array] comments - the comments attached to the code object to be parsed into a docstring and meta tags.

attach_full_source

public Object attach_full_source(source)

Manually attaches full source code for an object given the source as a String

Parameters:
[String] source - the source code for the object

attach_source

public Object attach_source(statement, file = nil)

Attaches source code to a code object with an optional file location

Parameters:
[Statement, String] statement - the Statement holding the source code or the raw source as a String for the definition of the code object only (not the block)
[String] file - the filename the source resides in

attributes

public Object attributes

Returns the value of attribute attributes


attributes=

public Object attributes=(value)

Sets the attribute attributes

Parameters:
value - the value to set the attribute attributes to.

children

public Object children

Returns the value of attribute children


children=

public Object children=(value)

Sets the attribute children

Parameters:
value - the value to set the attribute children to.

docstring

public Object docstring

Returns the value of attribute docstring


docstring=

public Object docstring=(value)

Sets the attribute docstring

Parameters:
value - the value to set the attribute docstring to.

file

public Object file

Returns the value of attribute file


file=

public Object file=(value)

Sets the attribute file

Parameters:
value - the value to set the attribute file to.

format

public String format(type = :html)

Returns a code object formatted as a given type, defaults to html.

Parameters:
[Symbol] format - the output format to generate
Returns:
the code object formatted by the specified format

full_source

public Object full_source

Returns the value of attribute full_source


full_source=

public Object full_source=(value)

Sets the attribute full_source

Parameters:
value - the value to set the attribute full_source to.

has_tag?

public Boolean has_tag?(name)

Returns true if at least one tag by the name name was declared

Parameters:
[String] name - the tag name to search for
Returns:
whether or not the tag name was declared

line

public Object line

Returns the value of attribute line


line=

public Object line=(value)

Sets the attribute line

Parameters:
value - the value to set the attribute line to.

name

public Object name

Returns the value of attribute name


name=

public Object name=(value)

Sets the attribute name

Parameters:
value - the value to set the attribute name to.

parent

public Object parent

Returns the value of attribute parent


parent=

public Object parent=(value)

Sets the parent object and registers the object path with the Namespace. If the object was already registered to an old path, it will be removed from the namespace.

Parameters:
[CodeObject] value - the new parent object
See Also:
Namespace

path

public Object path

Returns the unique path for this code object. The resulting path will be a Ruby style path name of the namespace the object resides in plus the object name delimited by a "::" or "#" depending on if the object is an instance level object or a class level object.

Example:


scope

public Object scope

Returns the value of attribute scope


scope=

public Object scope=(value)

Sets the attribute scope

Parameters:
value - the value to set the attribute scope to.

source

public Object source

Returns the value of attribute source


source=

public Object source=(value)

Sets the attribute source

Parameters:
value - the value to set the attribute source to.

tag

public BaseTag tag(name)

Convenience method to return the first tag object in the list of tag objects of that name

Example:

  doc = YARD::Documentation.new("@return zero when nil")
  doc.tag("return").text  # => "zero when nil"

Parameters:
[#to_s] name - the tag name to return data for
Returns:
the first tag in the list of #tags

tags

public Array tags(name = nil)

Returns a list of tags specified by name or all tags if name is not specified.

Parameters:
name - the tag name to return data for, or nil for all tags
Returns:
the list of tags by the specified tag name

to_s

public Object to_s


type

public Object type

Returns the value of attribute type


type=

public Object type=(value)

Sets the attribute type

Parameters:
value - the value to set the attribute type to.

visibility

public Object visibility

Returns the value of attribute visibility


visibility=

public Object visibility=(value)

Sets the attribute visibility

Parameters:
value - the value to set the attribute visibility to.