Class: YARD::CodeObjects::NamespaceObject
- 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).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#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.
-
#child(opts = {}) ⇒ Base?
Looks for a child that matches the attributes specified by
opts
. -
#children ⇒ Array<Base>
readonly
The list of objects defined in this namespace.
-
#class_attributes ⇒ Hash
Only the class attributes.
-
#class_mixins ⇒ Array<ModuleObject>
readonly
Class mixins.
-
#constants(opts = {}) ⇒ Array<ConstantObject>
Returns all constants in the namespace.
-
#cvars ⇒ Array<ClassVariableObject>
Returns class variables defined in this namespace.
-
#groups ⇒ Array<String>
A list of ordered group names inside the namespace.
-
#included_constants ⇒ Array<ConstantObject>
Returns constants included from any mixins.
-
#included_meths(opts = {}) ⇒ Object
Returns methods included from any mixins that match the attributes specified by
opts
. -
#instance_attributes ⇒ Hash
Only the instance attributes.
-
#instance_mixins ⇒ Array<ModuleObject>
readonly
Instance mixins.
-
#meths(opts = {}) ⇒ Array<MethodObject>
Returns all methods that match the attributes specified by
opts
. -
#mixins(*scopes) ⇒ Array<ModuleObject>
Returns for specific scopes.
Instance Method Summary collapse
-
#initialize(namespace, name, *args, &block) ⇒ NamespaceObject
constructor
Creates a new namespace object inside
namespace
withname
.
Constructor Details
#initialize(namespace, name, *args, &block) ⇒ NamespaceObject
Creates a new namespace object inside namespace
with name
.
59 60 61 62 63 64 65 66 67 |
# File 'lib/yard/code_objects/namespace_object.rb', line 59 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.
47 48 49 |
# File 'lib/yard/code_objects/namespace_object.rb', line 47 def aliases @aliases end |
#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.
42 43 44 |
# File 'lib/yard/code_objects/namespace_object.rb', line 42 def attributes @attributes end |
#child(opts = {}) ⇒ Base?
Looks for a child that matches the attributes specified by opts
.
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/yard/code_objects/namespace_object.rb', line 89 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 |
#children ⇒ Array<Base> (readonly)
The list of objects defined in this namespace
19 20 21 |
# File 'lib/yard/code_objects/namespace_object.rb', line 19 def children @children end |
#class_attributes ⇒ Hash
Only the class attributes
72 73 74 |
# File 'lib/yard/code_objects/namespace_object.rb', line 72 def class_attributes attributes[:class] end |
#class_mixins ⇒ Array<ModuleObject> (readonly)
Class mixins
51 52 53 |
# File 'lib/yard/code_objects/namespace_object.rb', line 51 def class_mixins @class_mixins end |
#constants(opts = {}) ⇒ Array<ConstantObject>
Returns all constants in the namespace
167 168 169 170 171 |
# File 'lib/yard/code_objects/namespace_object.rb', line 167 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.
189 190 191 |
# File 'lib/yard/code_objects/namespace_object.rb', line 189 def cvars children.select {|o| o.is_a? ClassVariableObject } end |
#groups ⇒ Array<String>
Returns a list of ordered group names inside the namespace.
15 16 17 |
# File 'lib/yard/code_objects/namespace_object.rb', line 15 def groups @groups end |
#included_constants ⇒ Array<ConstantObject>
Returns constants included from any mixins
175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/yard/code_objects/namespace_object.rb', line 175 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 = {}) ⇒ Object
Returns methods included from any mixins that match the attributes specified by opts
. If no options are specified, returns all included methods.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/yard/code_objects/namespace_object.rb', line 147 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
79 80 81 |
# File 'lib/yard/code_objects/namespace_object.rb', line 79 def instance_attributes attributes[:instance] end |
#instance_mixins ⇒ Array<ModuleObject> (readonly)
Instance mixins
55 56 57 |
# File 'lib/yard/code_objects/namespace_object.rb', line 55 def instance_mixins @instance_mixins end |
#meths(opts = {}) ⇒ Array<MethodObject>
Returns all methods that match the attributes specified by opts
. If no options are provided, returns all methods.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/yard/code_objects/namespace_object.rb', line 116 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.
197 198 199 200 201 |
# File 'lib/yard/code_objects/namespace_object.rb', line 197 def mixins(*scopes) return class_mixins if scopes == [:class] return instance_mixins if scopes == [:instance] class_mixins | instance_mixins end |