I had this idea too but validating these fields is not out of the box
anymore (as the keys in the hash aren't true attributes).
What I did :
class Instance
class << self
def for_entity(entity)
klass = Class.new(self)
name = "InstanceOf#{
entity.id}"
if #some condition about entity#
klass.key(:blop, Integer)
end
...
Instance.const_set(name, klass)
klass
end
end
end
Instance.for_entity(Entity.first).new
It works well but it defines a lot of classes in Instance's namespace.
Aurélien