Module: Sequel::Plugins::Subclasses::ClassMethods

Defined in:
lib/sequel/plugins/subclasses.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#on_subclassObject (readonly)

Callable object that should be called with every descendent class created.



37
38
39
# File 'lib/sequel/plugins/subclasses.rb', line 37

def on_subclass
  @on_subclass
end

#subclassesObject (readonly)

All subclasses for the current model. Does not include the model itself.



41
42
43
# File 'lib/sequel/plugins/subclasses.rb', line 41

def subclasses
  @subclasses
end

Instance Method Details

#descendentsObject

All descendent classes of this model.



44
45
46
# File 'lib/sequel/plugins/subclasses.rb', line 44

def descendents
  Sequel.synchronize{subclasses.dup}.map{|x| [x] + x.send(:descendents)}.flatten
end

#inherited(subclass) ⇒ Object

Add the subclass to this model's current subclasses, and initialize a new subclasses instance variable in the subclass.



53
54
55
56
57
# File 'lib/sequel/plugins/subclasses.rb', line 53

def inherited(subclass)
  super
  Sequel.synchronize{subclasses << subclass}
  on_subclass.call(subclass) if on_subclass
end