Class: YARD::CodeObjects::NamespaceObject
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Base
|
|
Instance Chain:
self,
Base
|
|
Inherits: |
YARD::CodeObjects::Base
|
Defined in: | lib/yard/code_objects/namespace_object.rb |
Overview
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
).
Class Method Summary
-
.new(namespace, name, *args, &block) ⇒ NamespaceObject
constructor
Creates a new namespace object inside
namespace
withname
.
Base
- Inherited
Instance Attribute Summary
-
#aliases ⇒ Hash
readonly
A hash containing two keys,
:class
and:instance
, each containing a hash of objects and their alias names. -
#attributes ⇒ Hash
readonly
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. -
#children ⇒ Array<Base>
readonly
The list of objects defined in this namespace.
-
#class_mixins ⇒ Array<ModuleObject>
readonly
Class mixins.
- #groups ⇒ Array<String> rw
-
#instance_mixins ⇒ Array<ModuleObject>
readonly
Instance mixins.
Base
- Inherited
#base_docstring | The non-localized documentation string associated with the object. |
#dynamic | Marks whether or not the method is conditionally defined at runtime. |
#dynamic? | Is the object defined conditionally at runtime? |
#files | The files the object was defined in. |
#group, | |
#namespace | The namespace the object is defined in. |
#namespace= | Sets the namespace the object is defined in. |
#parent | Alias for Base#namespace. |
#root?, | |
#signature | The one line signature representing an object. |
#source | The source code associated with the object. |
#source= | Attaches source code to a code object with an optional file location. |
#source_type | Language of the source code associated with the object. |
#visibility, #visibility= |
Instance Method Summary
-
#child(opts = {}) ⇒ Base?
Looks for a child that matches the attributes specified by
opts
. -
#class_attributes ⇒ Hash
Only the class attributes.
-
#constants(opts = {}) ⇒ Array<ConstantObject>
Returns all constants in the namespace.
-
#cvars ⇒ Array<ClassVariableObject>
Returns class variables defined in this namespace.
-
#included_constants ⇒ Array<ConstantObject>
Returns constants included from any mixins.
-
#included_meths(opts = {})
Returns methods included from any mixins that match the attributes specified by
opts
. -
#instance_attributes ⇒ Hash
Only the instance attributes.
-
#meths(opts = {}) ⇒ Array<MethodObject>
Returns all methods that match the attributes specified by
opts
. -
#mixins(*scopes) ⇒ Array<ModuleObject>
Returns for specific scopes.
Base
- Inherited
#== | Alias for Base#equal?. |
#[] | Accesses a custom attribute on the object. |
#[]= | Sets a custom attribute on the object. |
#add_file | Associates a file with a code object, optionally adding the line where it was defined. |
#add_tag | Add tags to the |
#copy_to | Copies all data in this object to another code object, except for uniquely identifying information (path, namespace, name, scope). |
#docstring | The documentation string associated with the object. |
#docstring= | Attaches a docstring to a code object by parsing the comments attached to the statement and filling the |
#eql? | Alias for Base#equal?. |
#equal? | Tests if another object is equal to this, including a proxy. |
#file | Returns the filename the object was first parsed at, taking definitions with docstrings first. |
#format | Renders the object using the templating system. |
#has_tag? | Tests if the |
#hash, | |
#initialize | Creates a new code object. |
#inspect | Inspects the object, returning the type and path. |
#line | Returns the line the object was first parsed at (or nil). |
#method_missing, | |
#name | The name of the object. |
#path | Represents the unique path of the object. |
#relative_path, | |
#sep | Override this method with a custom component separator. |
#tag | Gets a tag from the |
#tags | Gets a list of tags from the |
#title, #to_ary, | |
#to_s | Alias for Base#path. |
#type | Default type is the lowercase class name without the "Object" suffix. |
#format_source | Formats source code by removing leading indentation. |
#translate_docstring |
Constructor Details
.new(namespace, name, *args, &block) ⇒ NamespaceObject
Creates a new namespace object inside namespace
with name
.
# 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
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class YARD::CodeObjects::Base
Instance Attribute Details
#aliases ⇒ Hash (readonly)
A hash containing two keys, :class
and :instance
, each containing
a hash of objects and their alias names.
# File 'lib/yard/code_objects/namespace_object.rb', line 44
attr_reader :aliases
#attributes ⇒ Hash (readonly)
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.
# File 'lib/yard/code_objects/namespace_object.rb', line 39
attr_reader :attributes
#children ⇒ Array<Base> (readonly)
The list of objects defined in this namespace
# File 'lib/yard/code_objects/namespace_object.rb', line 16
attr_reader :children
#class_mixins ⇒ Array<ModuleObject> (readonly)
Class mixins
# File 'lib/yard/code_objects/namespace_object.rb', line 48
attr_reader :class_mixins
#groups ⇒ Array<String> (rw)
# File 'lib/yard/code_objects/namespace_object.rb', line 12
attr_accessor :groups
#instance_mixins ⇒ Array<ModuleObject> (readonly)
Instance mixins
# File 'lib/yard/code_objects/namespace_object.rb', line 52
attr_reader :instance_mixins
Instance Method Details
#child(opts = {}) ⇒ Base?
Looks for a child that matches the attributes specified by opts
.
# 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 unless value.is_a?(Array) ? value.include?(obj[meth]) : obj[meth] == value end end end end
#class_attributes ⇒ Hash
Only the class attributes
# File 'lib/yard/code_objects/namespace_object.rb', line 69
def class_attributes attributes[:class] end
#constants(opts = {}) ⇒ Array<ConstantObject>
Returns all constants in the namespace
# 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 ⇒ Array<ClassVariableObject>
Returns class variables defined in this namespace.
# File 'lib/yard/code_objects/namespace_object.rb', line 186
def cvars children.select {|o| o.is_a? ClassVariableObject } end
#included_constants ⇒ Array<ConstantObject>
Returns constants included from any mixins
# 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 = {})
Returns methods included from any mixins that match the attributes
specified by opts
. If no options are specified, returns all included
methods.
# 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 ⇒ Hash
Only the instance attributes
# File 'lib/yard/code_objects/namespace_object.rb', line 76
def instance_attributes attributes[:instance] end
#meths(opts = {}) ⇒ Array<MethodObject>
Returns all methods that match the attributes specified by opts
. If
no options are provided, returns all methods.
# 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) ⇒ Array<ModuleObject>
Returns for specific scopes. If no scopes are provided, returns all 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