lib/yard/code_objects/namespace_object.rb in yard-0.2.2 vs lib/yard/code_objects/namespace_object.rb in yard-0.2.3
- old
+ new
@@ -1,12 +1,14 @@
module YARD::CodeObjects
class NamespaceObject < Base
- attr_reader :children, :cvars, :meths, :constants, :mixins, :attributes, :aliases
+ attr_reader :children, :cvars, :meths, :constants, :attributes, :aliases
+ attr_reader :class_mixins, :instance_mixins
def initialize(namespace, name, *args, &block)
@children = CodeObjectList.new(self)
- @mixins = CodeObjectList.new(self)
+ @class_mixins = CodeObjectList.new(self)
+ @instance_mixins = CodeObjectList.new(self)
@attributes = SymbolHash[:class => SymbolHash.new, :instance => SymbolHash.new]
@aliases = {}
super
end
@@ -23,11 +25,11 @@
children.find {|o| o.name == opts.to_sym }
else
opts = SymbolHash[opts]
children.find do |obj|
opts.each do |meth, value|
- break false if obj[meth] != value
+ break false if !(value.is_a?(Array) ? value.include?(obj[meth]) : obj[meth] == value)
end
end
end
end
@@ -49,40 +51,47 @@
ourmeths + (opts[:included] ? included_meths(opts) : [])
end
def included_meths(opts = {})
- mixins.reverse.inject([]) do |list, mixin|
- if mixin.is_a?(Proxy)
- list
- else
- list += mixin.meths(opts).reject do |o|
- child(:name => o.name, :scope => o.scope) ||
- list.find {|o2| o2.name == o.name && o2.scope == o.scope }
+ opts = SymbolHash[:scope => [:instance, :class]].update(opts)
+ [opts[:scope]].flatten.map do |scope|
+ mixins(scope).reverse.inject([]) do |list, mixin|
+ next list if mixin.is_a?(Proxy)
+ arr = mixin.meths(opts.merge(:scope => :instance)).reject do |o|
+ 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
+ end.flatten
end
def constants(opts = {})
opts = SymbolHash[:included => true].update(opts)
consts = children.select {|o| o.is_a? ConstantObject }
consts + (opts[:included] ? included_constants : [])
end
def included_constants
- mixins.reverse.inject([]) do |list, mixin|
- if mixin.is_a?(Proxy)
- list
- else
+ instance_mixins.reverse.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
def cvars
children.select {|o| o.is_a? ClassVariableObject }
end
+
+ def mixins(*scopes)
+ return class_mixins if scopes == [:class]
+ return instance_mixins if scopes == [:instance]
+ class_mixins | instance_mixins
+ end
end
-end
\ No newline at end of file
+end