module Ardm::Ar::Inheritance::ClassMethods

Public Instance Methods

new(attrs={}, *a, &b) click to toggle source
Calls superclass method
# File lib/ardm/ar/inheritance.rb, line 19
def new(attrs={}, *a, &b)
  type = attrs && attrs.stringify_keys[inheritance_column.to_s]
  if type && type != name && type != self
    #puts "STI found for #{type} #{self}"
    con = type.is_a?(Class) ? type : type.constantize
    if con < self
      con.new(attrs, *a, &b)
    else
      raise "Tried to create subclass from #{type} (from key #{inheritance_column}) that is not a subclass of #{name}."
    end
  else
    #puts "No STI found for #{self} (#{attrs.inspect})"
    super
  end
end