Module: HTAuth::DescendantTracker

Included in:
Algorithm
Defined in:
lib/htauth/descendant_tracker.rb

Overview

Use by either

class Foo
  extend DescendantTracker
end

or

class Foo
  class << self
    include DescendantTracker
  end
end

It will track all the classes that inherit from the extended class and keep them in a Set that is available via the ‘children’ method.

Instance Method Summary collapse

Instance Method Details

#childrenObject

The list of children that are registered



33
34
35
36
# File 'lib/htauth/descendant_tracker.rb', line 33

def children
  @children = [] unless defined? @children
  @children
end

#find_child(method, *args) ⇒ Object

find the child that returns truthy for then given method and parameters



42
43
44
45
46
# File 'lib/htauth/descendant_tracker.rb', line 42

def find_child(method, *args)
  children.find do |child|
    child.send(method, *args)
  end
end

#inherited(klass) ⇒ Object



23
24
25
26
27
28
# File 'lib/htauth/descendant_tracker.rb', line 23

def inherited(klass)
  super
  return unless klass.instance_of?(Class)

  children << klass
end