Class: YARD::CodeObjects::NamespaceObject

### Home Classes Methods

### In Files

- lib/yard/code_objects/namespace_object.rb

### Parent

YARD::CodeObjects::Base

### Methods

- ::new
- #child
- #class_attributes
- #constants
- #cvars
- #included_constants
- #included_meths
- #instance_attributes
- #meths
- #mixins

### Files

- LICENSE.txt
- MIT.txt

### Class/Module Index

Quicksearch

- YARD
- YARD::CLI
- YARD::CLI::Command
- YARD::CLI::CommandParser
- YARD::CLI::Config
- YARD::CLI::Diff
- YARD::CLI::Display
- YARD::CLI::Gems
- YARD::CLI::Graph
- YARD::CLI::GraphOptions
- YARD::CLI::Help
- YARD::CLI::I18n
- YARD::CLI::List
- YARD::CLI::MarkupTypes
- YARD::CLI::Server
- YARD::CLI::Stats
- YARD::CLI::YRI
- YARD::CLI::Yardoc
- YARD::CLI::YardocOptions
- YARD::CLI::YardoptsCommand
- YARD::CodeObjects
- YARD::CodeObjects::Base
- YARD::CodeObjects::ClassObject
- YARD::CodeObjects::ClassVariableObject
- YARD::CodeObjects::CodeObjectList
- YARD::CodeObjects::ConstantObject
- YARD::CodeObjects::ExtendedMethodObject
- YARD::CodeObjects::ExtraFileObject
- YARD::CodeObjects::MacroObject
- YARD::CodeObjects::MethodObject
- YARD::CodeObjects::ModuleObject
- YARD::CodeObjects::NamespaceObject
- YARD::CodeObjects::Proxy
- YARD::CodeObjects::ProxyMethodError
- YARD::CodeObjects::RootObject
- YARD::Config
- YARD::Docstring
- YARD::DocstringParser
- YARD::Handlers
- YARD::Handlers::Base
- YARD::Handlers::C
- YARD::Handlers::C::AliasHandler
- YARD::Handlers::C::AttributeHandler
- YARD::Handlers::C::Base
- YARD::Handlers::C::ClassHandler
- YARD::Handlers::C::ConstantHandler
- YARD::Handlers::C::HandlerMethods
- YARD::Handlers::C::InitHandler
- YARD::Handlers::C::MethodHandler
- YARD::Handlers::C::MixinHandler
- YARD::Handlers::C::ModuleHandler
- YARD::Handlers::C::OverrideCommentHandler
- YARD::Handlers::C::PathHandler
- YARD::Handlers::C::StructHandler
- YARD::Handlers::C::SymbolHandler
- YARD::Handlers::HandlerAborted
- YARD::Handlers::NamespaceMissingError
- YARD::Handlers::Processor
- YARD::Handlers::Ruby
- YARD::Handlers::Ruby::AliasHandler
- YARD::Handlers::Ruby::AttributeHandler
- YARD::Handlers::Ruby::Base
- YARD::Handlers::Ruby::ClassConditionHandler
- YARD::Handlers::Ruby::ClassHandler
- YARD::Handlers::Ruby::ClassVariableHandler
- YARD::Handlers::Ruby::CommentHandler
- YARD::Handlers::Ruby::ConstantHandler
- YARD::Handlers::Ruby::DSLHandler
- YARD::Handlers::Ruby::DSLHandlerMethods
- YARD::Handlers::Ruby::ExceptionHandler
- YARD::Handlers::Ruby::ExtendHandler
- YARD::Handlers::Ruby::HandlesExtension
- YARD::Handlers::Ruby::Legacy
- YARD::Handlers::Ruby::Legacy::AliasHandler
- YARD::Handlers::Ruby::Legacy::AttributeHandler
- YARD::Handlers::Ruby::Legacy::Base
- YARD::Handlers::Ruby::Legacy::ClassConditionHandler
- YARD::Handlers::Ruby::Legacy::ClassHandler
- YARD::Handlers::Ruby::Legacy::ClassVariableHandler
- YARD::Handlers::Ruby::Legacy::CommentHandler
- YARD::Handlers::Ruby::Legacy::ConstantHandler
- YARD::Handlers::Ruby::Legacy::DSLHandler
- YARD::Handlers::Ruby::Legacy::ExceptionHandler
- YARD::Handlers::Ruby::Legacy::ExtendHandler
- YARD::Handlers::Ruby::Legacy::MethodHandler
- YARD::Handlers::Ruby::Legacy::MixinHandler
- YARD::Handlers::Ruby::Legacy::ModuleFunctionHandler
- YARD::Handlers::Ruby::Legacy::ModuleHandler
- YARD::Handlers::Ruby::Legacy::PrivateClassMethodHandler
- YARD::Handlers::Ruby::Legacy::PrivateConstantHandler
- YARD::Handlers::Ruby::Legacy::VisibilityHandler
- YARD::Handlers::Ruby::Legacy::YieldHandler
- YARD::Handlers::Ruby::MethodCallWrapper
- YARD::Handlers::Ruby::MethodConditionHandler
- YARD::Handlers::Ruby::MethodHandler
- YARD::Handlers::Ruby::MixinHandler
- YARD::Handlers::Ruby::ModuleFunctionHandler
- YARD::Handlers::Ruby::ModuleHandler
- YARD::Handlers::Ruby::PrivateClassMethodHandler
- YARD::Handlers::Ruby::PrivateConstantHandler
- YARD::Handlers::Ruby::StructHandlerMethods
- YARD::Handlers::Ruby::TestNodeWrapper
- YARD::Handlers::Ruby::VisibilityHandler
- YARD::Handlers::Ruby::YieldHandler
- YARD::I18n
- YARD::I18n::Locale
- YARD::I18n::Message
- YARD::I18n::Messages
- YARD::I18n::POParser
- YARD::I18n::PotGenerator
- YARD::I18n::Text
- YARD::Logger
- YARD::Options
- YARD::Parser
- YARD::Parser::Base
- YARD::Parser::C
- YARD::Parser::C::BodyStatement
- YARD::Parser::C::CParser
- YARD::Parser::C::Comment
- YARD::Parser::C::CommentParser
- YARD::Parser::C::Statement
- YARD::Parser::C::ToplevelStatement
- YARD::Parser::OrderedParser
- YARD::Parser::ParserSyntaxError
- YARD::Parser::Ruby
- YARD::Parser::Ruby::AstNode
- YARD::Parser::Ruby::ClassNode
- YARD::Parser::Ruby::CommentNode
- YARD::Parser::Ruby::ConditionalNode
- YARD::Parser::Ruby::KeywordNode
- YARD::Parser::Ruby::Legacy
- YARD::Parser::Ruby::Legacy::RubyLex
- YARD::Parser::Ruby::Legacy::RubyLex::BufferedReader
- YARD::Parser::Ruby::Legacy::RubyParser
- YARD::Parser::Ruby::Legacy::RubyToken
- YARD::Parser::Ruby::Legacy::RubyToken::TkBlockContents
- YARD::Parser::Ruby::Legacy::RubyToken::TkError
- YARD::Parser::Ruby::Legacy::RubyToken::TkId
- YARD::Parser::Ruby::Legacy::RubyToken::TkKW
- YARD::Parser::Ruby::Legacy::RubyToken::TkNode
- YARD::Parser::Ruby::Legacy::RubyToken::TkOPASGN
- YARD::Parser::Ruby::Legacy::RubyToken::TkOp
- YARD::Parser::Ruby::Legacy::RubyToken::TkStatementEnd
- YARD::Parser::Ruby::Legacy::RubyToken::TkUnknownChar
- YARD::Parser::Ruby::Legacy::RubyToken::TkVal
- YARD::Parser::Ruby::Legacy::RubyToken::TkWhitespace
- YARD::Parser::Ruby::Legacy::RubyToken::Token
- YARD::Parser::Ruby::Legacy::Statement
- YARD::Parser::Ruby::Legacy::StatementList
- YARD::Parser::Ruby::Legacy::TokenList
- YARD::Parser::Ruby::LiteralNode
- YARD::Parser::Ruby::LoopNode
- YARD::Parser::Ruby::MethodCallNode
- YARD::Parser::Ruby::MethodDefinitionNode
- YARD::Parser::Ruby::ModuleNode
- YARD::Parser::Ruby::ParameterNode
- YARD::Parser::Ruby::ReferenceNode
- YARD::Parser::Ruby::RipperParser
- YARD::Parser::Ruby::RubyParser
- YARD::Parser::SourceParser
- YARD::Parser::UndocumentableError
- YARD::Rake
- YARD::Rake::YardocTask
- YARD::Registry
- YARD::RegistryStore
- YARD::Serializers
- YARD::Serializers::Base
- YARD::Serializers::FileSystemSerializer
- YARD::Serializers::ProcessSerializer
- YARD::Serializers::StdoutSerializer
- YARD::Serializers::YardocSerializer
- YARD::Server
- YARD::Server::Adapter
- YARD::Server::Commands
- YARD::Server::Commands::Base
- YARD::Server::Commands::DisplayFileCommand
- YARD::Server::Commands::DisplayObjectCommand
- YARD::Server::Commands::FramesCommand
- YARD::Server::Commands::LibraryCommand
- YARD::Server::Commands::LibraryIndexCommand
- YARD::Server::Commands::LibraryOptions
- YARD::Server::Commands::ListCommand
- YARD::Server::Commands::SearchCommand
- YARD::Server::Commands::StaticFileCommand
- YARD::Server::DocServerHelper
- YARD::Server::DocServerSerializer
- YARD::Server::FinishRequest
- YARD::Server::LibraryNotPreparedError
- YARD::Server::LibraryVersion
- YARD::Server::NotFoundError
- YARD::Server::RackAdapter
- YARD::Server::RackMiddleware
- YARD::Server::Router
- YARD::Server::StaticCaching
- YARD::Server::WebrickAdapter
- YARD::Server::WebrickServlet
- YARD::StubProxy
- YARD::Tags
- YARD::Tags::AttributeDirective
- YARD::Tags::DefaultFactory
- YARD::Tags::DefaultTag
- YARD::Tags::Directive
- YARD::Tags::EndGroupDirective
- YARD::Tags::GroupDirective
- YARD::Tags::Library
- YARD::Tags::MacroDirective
- YARD::Tags::MethodDirective
- YARD::Tags::OptionTag
- YARD::Tags::OverloadTag
- YARD::Tags::ParseDirective
- YARD::Tags::RefTag
- YARD::Tags::RefTagList
- YARD::Tags::ScopeDirective
- YARD::Tags::Tag
- YARD::Tags::TagFormatError
- YARD::Tags::VisibilityDirective
- YARD::Templates
- YARD::Templates::Engine
- YARD::Templates::ErbCache
- YARD::Templates::Helpers
- YARD::Templates::Helpers::BaseHelper
- YARD::Templates::Helpers::FilterHelper
- YARD::Templates::Helpers::HtmlHelper
- YARD::Templates::Helpers::HtmlSyntaxHighlightHelper
- YARD::Templates::Helpers::Markup
- YARD::Templates::Helpers::Markup::RDocMarkdown
- YARD::Templates::Helpers::Markup::RDocMarkup
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkup
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkup::RDocMarkupToHtml
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkupToHtml
- YARD::Templates::Helpers::MarkupHelper
- YARD::Templates::Helpers::MethodHelper
- YARD::Templates::Helpers::ModuleHelper
- YARD::Templates::Helpers::TextHelper
- YARD::Templates::Helpers::UMLHelper
- YARD::Templates::Section
- YARD::Templates::Template
- YARD::Templates::Template::ClassMethods
- YARD::Templates::TemplateOptions
- YARD::Verifier
- Gem
- Gem::DocManager
- Gem::SourceIndex
- Gem::Specification
- Rack
- Rack::Request
- WEBrick
- WEBrick::HTTPRequest
- Array
- File
- Hash
- Insertion
- Module
- Object
- String
- SymbolHash

No matching classes.

# YARD::CodeObjects::NamespaceObject

A "namespace" is any object that can store other objects within itself. The two main Ruby objects that can act as namespaces are modules ({ModuleObject}) and classes ({ClassObject}).

### Attributes

aliases[R]

A hash containing two keys, :class and :instance, each containing a hash of objects and their alias names. @return [Hash] a list of methods

attributes[R]

A hash containing two keys, class and instance, each containing the attribute name with a { :read, :write } hash for the read and write objects respectively.

@example The attributes of an object

    >> Registry.at('YARD::Docstring').attributes
    => {
          :class => { },
          :instance => {
            :ref_tags => {
              :read => #<yardoc method YARD::Docstring#ref_tags>,
              :write => nil
            },
            :object => {
              :read => #<yardoc method YARD::Docstring#object>,
              :write => #<yardoc method YARD::Docstring#object=>
             },
             ...
          }
        }

@return [Hash] a list of methods

child[W]
children[R]

The list of objects defined in this namespace @return [Array<Base>] a list of objects

class_attributes[W]
class_mixins[R]

Class mixins @return [Array<ModuleObject>] a list of mixins

constants[W]
cvars[W]
groups[RW]

@return [Array<String>] a list of ordered group names inside the namespace @since 0.6.0

included_constants[W]
included_meths[W]
instance_attributes[W]
instance_mixins[R]

Instance mixins @return [Array<ModuleObject>] a list of mixins

meths[W]
mixins[W]

### Public Class Methods

new(namespace, name, *args, &block) click to toggle source

Creates a new namespace object inside `namespace` with `name`. @see Base#initialize

    # File lib/yard/code_objects/namespace_object.rb, line 56
    def initialize(namespace, name, *args, &block)
      @children = CodeObjectList.new(self)
      @class_mixins = CodeObjectList.new(self)
      @instance_mixins = CodeObjectList.new(self)
      @attributes = SymbolHash[:class => SymbolHash.new, :instance => SymbolHash.new]
      @aliases = {}
      @groups = []
      super
    end

### Public Instance Methods

child(opts = {}) click to toggle source

Looks for a child that matches the attributes specified by `opts`.

@example Finds a child by name and scope

    namespace.child(:name => :to_s, :scope => :instance)
    # => #<yardoc method MyClass#to_s>

@return [Base, nil] the first matched child object, or nil

    # File lib/yard/code_objects/namespace_object.rb, line 86
    def child(opts = {})
      if !opts.is_a?(Hash)
        children.find {|o| o.name == opts.to_sym }
      else
        opts = SymbolHash[opts]
        children.find do |obj|
          opts.each do |meth, value|
            break false if !(value.is_a?(Array) ? value.include?(obj[meth]) : obj[meth] == value)
          end
        end
      end
    end

class_attributes() click to toggle source

Only the class attributes @return [Hash] a list of method names and their read/write objects @see attributes

    # File lib/yard/code_objects/namespace_object.rb, line 69
    def class_attributes
      attributes[:class]
    end

constants(opts = {}) click to toggle source

Returns all constants in the namespace

@option opts [Boolean] :included (true) whether or not to include

    mixed in constants in list

@return [Array<ConstantObject>] a list of constant objects

    # File lib/yard/code_objects/namespace_object.rb, line 164
    def constants(opts = {})
      opts = SymbolHash[:included => true].update(opts)
      consts = children.select {|o| o.is_a? ConstantObject }
      consts + (opts[:included] ? included_constants : [])
    end

cvars() click to toggle source

Returns class variables defined in this namespace. @return [Array<ClassVariableObject>] a list of class variable objects

    # File lib/yard/code_objects/namespace_object.rb, line 186
    def cvars
      children.select {|o| o.is_a? ClassVariableObject }
    end

included_constants() click to toggle source

Returns constants included from any mixins @return [Array<ConstantObject>] a list of constant objects

    # File lib/yard/code_objects/namespace_object.rb, line 172
    def included_constants
      instance_mixins.inject([]) do |list, mixin|
        if mixin.respond_to? :constants
          list += mixin.constants.reject do |o|
            child(:name => o.name) || list.find {|o2| o2.name == o.name }
          end
        else
          list
        end
      end
    end

included_meths(opts = {}) click to toggle source

Returns methods included from any mixins that match the attributes specified by `opts`. If no options are specified, returns all included methods.

@option opts [Array<Symbol>, Symbol] :visibility ([:public, :private,

    :protected]) the visibility of the methods to list. Can be an array or
    single value.

@option opts [Array<Symbol>, Symbol] :scope ([:class, :instance]) the

    scope of the methods to list. Can be an array or single value.

@option opts [Boolean] :included (true) whether to include mixed in

    methods in the list.

@see meths

    # File lib/yard/code_objects/namespace_object.rb, line 144
    def included_meths(opts = {})
      opts = SymbolHash[:scope => [:instance, :class]].update(opts)
      [opts[:scope]].flatten.map do |scope|
        mixins(scope).inject([]) do |list, mixin|
          next list if mixin.is_a?(Proxy)
          arr = mixin.meths(opts.merge(:scope => :instance)).reject do |o|
            next false if opts[:all]
            child(:name => o.name, :scope => scope) || list.find {|o2| o2.name == o.name }
          end
          arr.map! {|o| ExtendedMethodObject.new(o) } if scope == :class
          list + arr
        end
      end.flatten
    end

instance_attributes() click to toggle source

Only the instance attributes @return [Hash] a list of method names and their read/write objects @see attributes

    # File lib/yard/code_objects/namespace_object.rb, line 76
    def instance_attributes
      attributes[:instance]
    end

meths(opts = {}) click to toggle source

Returns all methods that match the attributes specified by `opts`. If no options are provided, returns all methods.

@example Finds all private and protected class methods

    namespace.meths(:visibility => [:private, :protected], :scope => :class)
    # => [#<yardoc method MyClass.privmeth>, #<yardoc method MyClass.protmeth>]

@option opts [Array<Symbol>, Symbol] :visibility ([:public, :private,

    :protected]) the visibility of the methods to list. Can be an array or
    single value.

@option opts [Array<Symbol>, Symbol] :scope ([:class, :instance]) the

    scope of the methods to list. Can be an array or single value.

@option opts [Boolean] :included (true) whether to include mixed in

    methods in the list.

@return [Array<MethodObject>] a list of method objects

    # File lib/yard/code_objects/namespace_object.rb, line 113
    def meths(opts = {})
      opts = SymbolHash[
        :visibility => [:public, :private, :protected],
        :scope => [:class, :instance],
        :included => true
      ].update(opts)

      opts[:visibility] = [opts[:visibility]].flatten
      opts[:scope] = [opts[:scope]].flatten

      ourmeths = children.select do |o|
        o.is_a?(MethodObject) &&
          opts[:visibility].include?(o.visibility) &&
          opts[:scope].include?(o.scope)
      end

      ourmeths + (opts[:included] ? included_meths(opts) : [])
    end

mixins(*scopes) click to toggle source

Returns for specific scopes. If no scopes are provided, returns all mixins. @param [Array<Symbol>] scopes a list of scopes (:class, :instance) to

    return mixins for. If this is empty, all scopes will be returned.

@return [Array<ModuleObject>] a list of mixins

    # File lib/yard/code_objects/namespace_object.rb, line 194
    def mixins(*scopes)
      return class_mixins if scopes == [:class]
      return instance_mixins if scopes == [:instance]
      class_mixins | instance_mixins
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.