module ActiveRecordEx::PolymorphicBuild::ClassMethods

Public Instance Methods

new_with_typing(attrs = {}, options = {}) click to toggle source
# File lib/active-record-ex/polymorphic_build.rb, line 19
def new_with_typing(attrs = {}, options = {})
  if attrs[:type] && (klass = attrs[:type].constantize) < self
    klass.new(attrs, options)
  elsif attrs[:type] && !((klass = attrs[:type].constantize) <= self)
    raise ArgumentError.new("Attempting to instantiate #{klass}, which is not a subclass of #{self}")
  else
    new_without_typing(attrs, options)
  end
end