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.



47
48
49
# File 'lib/sequel/plugins/subclasses.rb', line 47

def on_subclass
  @on_subclass
end

#subclassesObject (readonly)

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



51
52
53
# File 'lib/sequel/plugins/subclasses.rb', line 51

def subclasses
  @subclasses
end

Instance Method Details

#descendentsObject

All descendent classes of this model.



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

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

#freeze_descendentsObject

Freeze all descendent classes. This also finalizes the associations for those classes before freezing.



60
61
62
# File 'lib/sequel/plugins/subclasses.rb', line 60

def freeze_descendents
  descendents.each(&:finalize_associations).each(&:freeze)
end

#inherited(subclass) ⇒ Object

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



69
70
71
72
73
# File 'lib/sequel/plugins/subclasses.rb', line 69

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