Module: Chef::Mixin::DescendantsTracker

Included in:
Provides, Resource::File::Verification
Defined in:
lib/chef/mixin/descendants_tracker.rb

Constant Summary

@@direct_descendants =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.descendants(klass) ⇒ Object



37
38
39
40
41
# File 'lib/chef/mixin/descendants_tracker.rb', line 37

def descendants(klass)
  arr = []
  accumulate_descendants(klass, arr)
  arr
end

.direct_descendants(klass) ⇒ Object



33
34
35
# File 'lib/chef/mixin/descendants_tracker.rb', line 33

def direct_descendants(klass)
  @@direct_descendants[klass] || []
end

.find_descendants_by_name(klass, name) ⇒ Object



43
44
45
# File 'lib/chef/mixin/descendants_tracker.rb', line 43

def find_descendants_by_name(klass, name)
  descendants(klass).first { |c| c.name == name }
end

.store_inherited(klass, descendant) ⇒ Object

This is the only method that is not thread safe, but is only ever called during the eager loading phase.



49
50
51
# File 'lib/chef/mixin/descendants_tracker.rb', line 49

def store_inherited(klass, descendant)
  (@@direct_descendants[klass] ||= []) << descendant
end

Instance Method Details

#descendantsObject



76
77
78
# File 'lib/chef/mixin/descendants_tracker.rb', line 76

def descendants
  DescendantsTracker.descendants(self)
end

#direct_descendantsObject



68
69
70
# File 'lib/chef/mixin/descendants_tracker.rb', line 68

def direct_descendants
  DescendantsTracker.direct_descendants(self)
end

#find_descendants_by_name(name) ⇒ Object



72
73
74
# File 'lib/chef/mixin/descendants_tracker.rb', line 72

def find_descendants_by_name(name)
  DescendantsTracker.find_descendants_by_name(self, name)
end

#inherited(base) ⇒ Object



63
64
65
66
# File 'lib/chef/mixin/descendants_tracker.rb', line 63

def inherited(base)
  DescendantsTracker.store_inherited(self, base)
  super
end