Class: Yoda::Store::Query::Associators::AssociateAncestors::Processor
- Inherits:
-
Object
- Object
- Yoda::Store::Query::Associators::AssociateAncestors::Processor
- Defined in:
- lib/yoda/store/query/associators/associate_ancestors.rb
Instance Attribute Summary collapse
- #registry ⇒ Registry readonly
Instance Method Summary collapse
- #find_metaclass_superclass_ancestors(obj) ⇒ Enumerator<Objects::NamespaceObject>
- #find_mixins(obj) ⇒ Enumerator<Objects::NamespaceObject>
- #find_superclass_ancestors(obj) ⇒ Enumerator<Objects::NamespaceObject>
-
#initialize(registry) ⇒ Processor
constructor
A new instance of Processor.
- #met ⇒ Set<Objects::Base>
- #process(scope) ⇒ Enumerator<Objects::NamespaceObject>
Constructor Details
#initialize(registry) ⇒ Processor
Returns a new instance of Processor.
42 43 44 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 42 def initialize(registry) @registry = registry end |
Instance Attribute Details
#registry ⇒ Registry (readonly)
39 40 41 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 39 def registry @registry end |
Instance Method Details
#find_metaclass_superclass_ancestors(obj) ⇒ Enumerator<Objects::NamespaceObject>
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 96 def (obj) base_class = registry.find(obj.base_class_address) if base_class && base_class.is_a?(Objects::ClassObject) && base_class.superclass_path ( = FindMetaClass.new(registry).find(base_class.superclass_path || 'Object')) ? process() : [] elsif base_class (class_object = registry.find('Class')) ? process(class_object) : [] else [] end end |
#find_mixins(obj) ⇒ Enumerator<Objects::NamespaceObject>
74 75 76 77 78 79 80 81 82 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 74 def find_mixins(obj) Enumerator.new do |yielder| obj.mixin_addresses.each do |address| if el = registry.find(address.to_s) yielder << el end end end end |
#find_superclass_ancestors(obj) ⇒ Enumerator<Objects::NamespaceObject>
86 87 88 89 90 91 92 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 86 def find_superclass_ancestors(obj) if obj.superclass_path && super_class = FindConstant.new(registry).find(obj.superclass_path) process(super_class) else [] end end |
#met ⇒ Set<Objects::Base>
48 49 50 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 48 def met @met ||= Set.new end |
#process(scope) ⇒ Enumerator<Objects::NamespaceObject>
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 54 def process(scope) fail CircularReferenceError, scope if met.include?(scope) met.add(scope) Enumerator.new do |yielder| if scope.is_a?(Objects::NamespaceObject) yielder << scope find_mixins(scope).each { |mixin| yielder << mixin } if scope.is_a?(Objects::MetaClassObject) (scope).each { |obj| yielder << obj } elsif scope.is_a?(Objects::ClassObject) find_superclass_ancestors(scope).each { |obj| yielder << obj } end end end end |