Class: Yoda::Store::Query::Associators::AssociateAncestors::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/store/query/associators/associate_ancestors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry) ⇒ Processor

Returns a new instance of Processor.

Parameters:



42
43
44
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 42

def initialize(registry)
  @registry = registry
end

Instance Attribute Details

#registryRegistry (readonly)

Returns:



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>

Parameters:

Returns:



96
97
98
99
100
101
102
103
104
105
# File 'lib/yoda/store/query/associators/associate_ancestors.rb', line 96

def find_metaclass_superclass_ancestors(obj)
  base_class = registry.find(obj.base_class_address)
  if base_class && base_class.is_a?(Objects::ClassObject) && base_class.superclass_path
    (meta_class = FindMetaClass.new(registry).find(base_class.superclass_path || 'Object')) ? process(meta_class) : []
  elsif base_class
    (class_object = registry.find('Class')) ? process(class_object) : []
  else
    []
  end
end

#find_mixins(obj) ⇒ Enumerator<Objects::NamespaceObject>

Parameters:

Returns:



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>

Parameters:

Returns:



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

#metSet<Objects::Base>

Returns:



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>

Parameters:

Returns:



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)
        find_metaclass_superclass_ancestors(scope).each { |obj| yielder << obj }
      elsif scope.is_a?(Objects::ClassObject)
        find_superclass_ancestors(scope).each { |obj| yielder << obj }
      end
    end
  end
end