Class: Yoda::Store::Query::AncestorTree
- Inherits:
-
Object
- Object
- Yoda::Store::Query::AncestorTree
show all
- Defined in:
- lib/yoda/store/query/ancestor_tree.rb
Defined Under Namespace
Classes: CircularReferenceError, Visitor
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(registry:, object:) ⇒ AncestorTree
Returns a new instance of AncestorTree.
48
49
50
51
|
# File 'lib/yoda/store/query/ancestor_tree.rb', line 48
def initialize(registry:, object:)
@registry = registry
@object = object
end
|
Instance Attribute Details
44
45
46
|
# File 'lib/yoda/store/query/ancestor_tree.rb', line 44
def object
@object
end
|
41
42
43
|
# File 'lib/yoda/store/query/ancestor_tree.rb', line 41
def registry
@registry
end
|
Instance Method Details
#ancestors(**kwargs) ⇒ Object
53
54
55
56
57
|
# File 'lib/yoda/store/query/ancestor_tree.rb', line 53
def ancestors(**kwargs)
Enumerator.new do |yielder|
walk_ancestors(Visitor.new(yielder), **kwargs)
end
end
|
60
61
62
63
64
65
66
67
68
|
# File 'lib/yoda/store/query/ancestor_tree.rb', line 60
def mixins
Enumerator.new do |yielder|
object.mixin_addresses.each do |address|
if el = registry.get(address.to_s)
yielder << el
end
end
end
end
|
71
72
73
|
# File 'lib/yoda/store/query/ancestor_tree.rb', line 71
def parent
@parent ||= superclass && AncestorTree.new(registry: registry, object: superclass)
end
|
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/yoda/store/query/ancestor_tree.rb', line 76
def superclass
return @superclass if instance_variable_defined?(:@superclass)
@superclass = begin
found_object = begin
if object.respond_to?(:base_class_address)
base_class_superclass
elsif object.respond_to?(:superclass_path)
if object.superclass_path
FindConstant.new(registry).find(object.superclass_path)
else
nil
end
else
nil
end
end
found_object&.namespace? ? found_object : nil
end
end
|