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.
34 35 36 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 34 def initialize(registry) @registry = registry end |
Instance Attribute Details
#registry ⇒ Registry (readonly)
31 32 33 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 31 def registry @registry end |
Instance Method Details
#find_metaclass_superclass_ancestors(obj) ⇒ Enumerator<Objects::NamespaceObject>
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 88 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>
66 67 68 69 70 71 72 73 74 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 66 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>
78 79 80 81 82 83 84 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 78 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>
40 41 42 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 40 def met @met ||= Set.new end |
#process(scope) ⇒ Enumerator<Objects::NamespaceObject>
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 46 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 |