Namespace

Included Modules

Class Index [+]

Quicksearch

RDoc::Context

A Context is something that can hold modules, classes, methods, attributes, aliases, requires, and includes. Classes, modules, and files are all Contexts.

Constants

TYPES

Types of methods

VISIBILITIES

Method visibilities

Attributes

aliases[R]

Aliased methods

attributes[R]

attr* methods

constants[R]

Constants defined

current_section[R]

Current section of documentation

in_files[R]

Files this context is found in

includes[R]

Modules this context includes

method_list[R]

Methods defined in this context

name[R]

Name of this class excluding namespace. See also full_name

requires[R]

Files this context requires

sections[R]

Sections in this context

unmatched_alias_lists[RW]

Aliases that haven’t been resolved to a method

visibility[R]

Current visibility of this context

Public Class Methods

new() click to toggle source

Creates an unnamed empty context with public visibility

# File lib/rdoc/context.rb, line 176
  def initialize
    super

    @in_files = []

    @name    ||= "unknown"
    @comment ||= ""
    @parent  = nil
    @visibility = :public

    @current_section = Section.new self, nil, nil
    @sections = [@current_section]

    initialize_methods_etc
    initialize_classes_and_modules
  end

Public Instance Methods

<=>(other) click to toggle source

Contexts are sorted by full_name

# File lib/rdoc/context.rb, line 220
  def <=>(other)
    full_name <=> other.full_name
  end
add_alias(an_alias) click to toggle source

Adds an_alias that is automatically resolved

# File lib/rdoc/context.rb, line 227
  def add_alias(an_alias)
    meth = find_instance_method_named(an_alias.old_name)

    if meth then
      add_alias_impl an_alias, meth
    else
      add_to @aliases, an_alias
      unmatched_alias_list = @unmatched_alias_lists[an_alias.old_name] ||= []
      unmatched_alias_list.push an_alias
    end

    an_alias
  end
add_alias_impl(an_alias, meth) click to toggle source

Adds an_alias pointing to meth

# File lib/rdoc/context.rb, line 244
  def add_alias_impl(an_alias, meth)
    new_meth = RDoc::AnyMethod.new an_alias.text, an_alias.new_name
    new_meth.is_alias_for = meth
    new_meth.singleton    = meth.singleton
    new_meth.params       = meth.params
    new_meth.comment = "Alias for \##{meth.name}"
    meth.add_alias new_meth
    add_method new_meth
  end
add_attribute(attribute) click to toggle source

Adds attribute

# File lib/rdoc/context.rb, line 257
  def add_attribute(attribute)
    add_to @attributes, attribute
  end
add_class(class_type, name, superclass = 'Object') click to toggle source

Adds a class named name with superclass.

Given class Container::Item RDoc assumes Container is a module unless it later sees class Container. add_class automatically upgrades name to a class in this case.

# File lib/rdoc/context.rb, line 268
  def add_class(class_type, name, superclass = 'Object')
    klass = add_class_or_module @classes, class_type, name, superclass

    # If the parser encounters Container::Item before encountering
    # Container, then it assumes that Container is a module.  This may not
    # be the case, so remove Container from the module list if present and
    # transfer any contained classes and modules to the new class.

    RDoc::TopLevel.lock.synchronize do
      mod = RDoc::TopLevel.modules_hash.delete klass.full_name

      if mod then
        klass.classes_hash.update mod.classes_hash
        klass.modules_hash.update mod.modules_hash
        klass.method_list.concat mod.method_list

        @modules.delete klass.name
      end

      RDoc::TopLevel.classes_hash[klass.full_name] = klass
    end

    klass
  end
add_class_or_module(collection, class_type, name, superclass = nil) click to toggle source

Instantiates a class_type named name and adds it the modules or classes Hash collection.

# File lib/rdoc/context.rb, line 297
  def add_class_or_module(collection, class_type, name, superclass = nil)
    full_name = if RDoc::TopLevel === self then # HACK
                  name
                else
                  "#{self.full_name}::#{name}"
                end
    mod = collection[name]

    if mod then
      mod.superclass = superclass unless mod.module?
    else
      all = nil

      RDoc::TopLevel.lock.synchronize do
        all = if class_type == RDoc::NormalModule then
                RDoc::TopLevel.modules_hash
              else
                RDoc::TopLevel.classes_hash
              end

        mod = all[full_name]
      end

      unless mod then
        mod = class_type.new name, superclass
      else
        # If the class has been encountered already, check that its
        # superclass has been set (it may not have been, depending on the
        # context in which it was encountered).
        if class_type == RDoc::NormalClass then
          mod.superclass = superclass unless mod.superclass
        end
      end

      unless @done_documenting then
        RDoc::TopLevel.lock.synchronize do
          all[full_name] = mod
        end
        collection[name] = mod
      end

      mod.section = @current_section
      mod.parent = self
    end

    mod
  end
add_constant(constant) click to toggle source

Adds constant

# File lib/rdoc/context.rb, line 348
  def add_constant(constant)
    add_to @constants, constant
  end
add_include(include) click to toggle source

Adds included module include

# File lib/rdoc/context.rb, line 355
  def add_include(include)
    add_to @includes, include
  end
add_method(method) click to toggle source

Adds method

# File lib/rdoc/context.rb, line 362
  def add_method(method)
    method.visibility = @visibility
    add_to @method_list, method

    unmatched_alias_list = @unmatched_alias_lists[method.name]
    if unmatched_alias_list then
      unmatched_alias_list.each do |unmatched_alias|
        add_alias_impl unmatched_alias, method
        @aliases.delete unmatched_alias
      end

      @unmatched_alias_lists.delete method.name
    end
  end
add_module(class_type, name) click to toggle source

Adds a module named name. If RDoc already knows name is a class then that class is returned instead. See also add_class

# File lib/rdoc/context.rb, line 381
  def add_module(class_type, name)
    return @classes[name] if @classes.key? name

    add_class_or_module @modules, class_type, name, nil
  end
add_require(require) click to toggle source

Adds require to this context’s top level

# File lib/rdoc/context.rb, line 390
  def add_require(require)
    if RDoc::TopLevel === self then
      add_to @requires, require
    else
      parent.add_require require
    end
  end
add_to(array, thing) click to toggle source

Adds thing to the collection array

# File lib/rdoc/context.rb, line 401
  def add_to(array, thing)
    array << thing if @document_self and not @done_documenting
    thing.parent = self
    thing.section = @current_section
  end
classes() click to toggle source

Array of classes in this context

# File lib/rdoc/context.rb, line 410
  def classes
    @classes.values
  end
classes_and_modules() click to toggle source

All classes and modules in this namespace

# File lib/rdoc/context.rb, line 417
  def classes_and_modules
    classes + modules
  end
classes_hash() click to toggle source

Hash of classes keyed by class name

# File lib/rdoc/context.rb, line 424
  def classes_hash
    @classes
  end
defined_in?(file) click to toggle source

Is part of this thing was defined in file?

# File lib/rdoc/context.rb, line 431
  def defined_in?(file)
    @in_files.include?(file)
  end
each_attribute() click to toggle source

Iterator for attributes

# File lib/rdoc/context.rb, line 438
  def each_attribute # :yields: attribute
    @attributes.each {|a| yield a}
  end
each_classmodule() click to toggle source

Iterator for classes and modules

# File lib/rdoc/context.rb, line 445
  def each_classmodule(&block) # :yields: module
    classes_and_modules.sort.each(&block)
  end
each_constant() click to toggle source

Iterator for constants

# File lib/rdoc/context.rb, line 452
  def each_constant # :yields: constant
    @constants.each {|c| yield c}
  end
each_include() click to toggle source

Iterator for included modules

# File lib/rdoc/context.rb, line 459
  def each_include # :yields: include
    @includes.each do |i| yield i end
  end
each_method() click to toggle source

Iterator for methods

# File lib/rdoc/context.rb, line 466
  def each_method # :yields: method
    @method_list.sort.each {|m| yield m}
  end
find_attribute_named(name) click to toggle source

Finds an attribute with name in this context

# File lib/rdoc/context.rb, line 473
  def find_attribute_named(name)
    @attributes.find { |m| m.name == name }
  end
find_constant_named(name) click to toggle source

Finds a constant with name in this context

# File lib/rdoc/context.rb, line 480
  def find_constant_named(name)
    @constants.find {|m| m.name == name}
  end
find_enclosing_module_named(name) click to toggle source

Find a module at a higher scope

# File lib/rdoc/context.rb, line 487
  def find_enclosing_module_named(name)
    parent && parent.find_module_named(name)
  end
find_file_named(name) click to toggle source

Finds a file with name in this context

# File lib/rdoc/context.rb, line 494
  def find_file_named(name)
    top_level.class.find_file_named(name)
  end
find_instance_method_named(name) click to toggle source

Finds an instance method with name in this context

# File lib/rdoc/context.rb, line 501
  def find_instance_method_named(name)
    @method_list.find { |meth| meth.name == name && !meth.singleton }
  end
find_local_symbol(symbol) click to toggle source

Finds a method, constant, attribute, module or files named symbol in this context

# File lib/rdoc/context.rb, line 509
  def find_local_symbol(symbol)
    find_method_named(symbol) or
    find_constant_named(symbol) or
    find_attribute_named(symbol) or
    find_module_named(symbol) or
    find_file_named(symbol)
  end
find_method_named(name) click to toggle source

Finds a instance or module method with name in this context

# File lib/rdoc/context.rb, line 520
  def find_method_named(name)
    @method_list.find { |meth| meth.name == name }
  end
find_module_named(name) click to toggle source

Find a module with name using ruby’s scoping rules

# File lib/rdoc/context.rb, line 527
  def find_module_named(name)
    res = @modules[name] || @classes[name]
    return res if res
    return self if self.name == name
    find_enclosing_module_named name
  end
find_symbol(symbol, method = nil) click to toggle source

Look up symbol. If method is non-nil, then we assume the symbol references a module that contains that method.

# File lib/rdoc/context.rb, line 538
  def find_symbol(symbol, method = nil)
    result = nil

    case symbol
    when /^::(.*)/ then
      result = top_level.find_symbol($1)
    when /::/ then
      modules = symbol.split(/::/)

      unless modules.empty? then
        module_name = modules.shift
        result = find_module_named(module_name)

        if result then
          modules.each do |name|
            result = result.find_module_named name
            break unless result
          end
        end
      end

    else
      # if a method is specified, then we're definitely looking for
      # a module, otherwise it could be any symbol
      if method then
        result = find_module_named symbol
      else
        result = find_local_symbol symbol
        if result.nil? then
          if symbol =~ /^[A-Z]/ then
            result = parent
            while result && result.name != symbol do
              result = result.parent
            end
          end
        end
      end
    end

    if result and method then
      fail unless result.respond_to? :find_local_symbol
      result = result.find_local_symbol(method)
    end

    result
  end
http_url(prefix) click to toggle source

URL for this with a prefix

# File lib/rdoc/context.rb, line 588
  def http_url(prefix)
    path = full_name
    path = path.gsub(/<<\s*(\w*)/, 'from-\1') if path =~ /<</
    path = [prefix] + path.split('::')

    File.join(*path.compact) + '.html'
  end
initialize_classes_and_modules() click to toggle source

Sets the defaults for classes and modules

# File lib/rdoc/context.rb, line 196
  def initialize_classes_and_modules
    @classes = {}
    @modules = {}
  end
initialize_methods_etc() click to toggle source

Sets the defaults for methods and so-forth

# File lib/rdoc/context.rb, line 204
  def initialize_methods_etc
    @method_list = []
    @attributes  = []
    @aliases     = []
    @requires    = []
    @includes    = []
    @constants   = []

    # This Hash maps a method name to a list of unmatched aliases (aliases of
    # a method not yet encountered).
    @unmatched_alias_lists = {}
  end
methods_by_type() click to toggle source

Breaks method_list into a nested hash by type (class or instance) and visibility (public, protected private)

# File lib/rdoc/context.rb, line 600
  def methods_by_type
    methods = {}

    TYPES.each do |type|
      visibilities = {}
      VISIBILITIES.each do |vis|
        visibilities[vis] = []
      end

      methods[type] = visibilities
    end

    each_method do |method|
      methods[method.type][method.visibility] << method
    end

    methods
  end
methods_matching(methods, singleton = false) click to toggle source

Yields Method and Attr entries matching the list of names in methods. Attributes are only returned when singleton is false.

# File lib/rdoc/context.rb, line 623
  def methods_matching(methods, singleton = false)
    count = 0

    @method_list.each do |m|
      if methods.include? m.name and m.singleton == singleton then
        yield m
        count += 1
      end
    end

    return if count == methods.size || singleton

    @attributes.each do |a|
      yield a if methods.include? a.name
    end
  end
modules() click to toggle source

Array of modules in this context

# File lib/rdoc/context.rb, line 643
  def modules
    @modules.values
  end
modules_hash() click to toggle source

Hash of modules keyed by module name

# File lib/rdoc/context.rb, line 650
  def modules_hash
    @modules
  end
ongoing_visibility=(visibility) click to toggle source

Changes the visibility for new methods to visibility

# File lib/rdoc/context.rb, line 657
  def ongoing_visibility=(visibility)
    @visibility = visibility
  end
record_location(top_level) click to toggle source

Record which file top_level is in

# File lib/rdoc/context.rb, line 664
  def record_location(top_level)
    @in_files << top_level unless @in_files.include?(top_level)
  end
remove_classes_and_modules() click to toggle source

Removes classes and modules when we see a :nodoc: all

# File lib/rdoc/context.rb, line 689
  def remove_classes_and_modules
    initialize_classes_and_modules
  end
remove_methods_etc() click to toggle source

If a class’s documentation is turned off after we’ve started collecting methods etc., we need to remove the ones we have

# File lib/rdoc/context.rb, line 672
  def remove_methods_etc
    initialize_methods_etc
  end
set_current_section(title, comment) click to toggle source

Creates a new section with title and comment

# File lib/rdoc/context.rb, line 696
  def set_current_section(title, comment)
    @current_section = Section.new self, title, comment
    @sections << @current_section
  end
set_visibility_for(methods, visibility, singleton = false) click to toggle source

Given an array methods of method names, set the visibility of each to visibility

# File lib/rdoc/context.rb, line 680
  def set_visibility_for(methods, visibility, singleton = false)
    methods_matching methods, singleton do |m|
      m.visibility = visibility
    end
  end
top_level() click to toggle source

Return the TopLevel that owns us

# File lib/rdoc/context.rb, line 704
  def top_level
    return @top_level if defined? @top_level
    @top_level = self
    @top_level = @top_level.parent until RDoc::TopLevel === @top_level
    @top_level
  end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.