Dynamic Single Table Inheritance with Rails Discussion
This was really fun. I wanted an easy way to introduce helpers to Notifications so by exposing them also as STI models, we could make them easily accessible with separate helper methods for each Notifier type. Super cool how flexible Ruby is for allowing these types of solutions!
I think I will use this to rewrite my event driven system. STI + to be able to have access to the aggregate context is a must ! Thanks Chris !
Really cool! How about the tests here. how can you ensure that a model will fail if it have not defined the required methods?
I miss something because when I do for example:
MentionNotifier.last
the error:
/scoping.rb:127:in value_for': undefined method
name' for nil:NilClass (NoMethodError)
scope_type[klass.name]
^^^^^
Or MentionNotifier.new
error:
/model_schema.rb:560:in load_schema': undefined method
synchronize' for nil:NilClass (NoMethodError)
@load_schema_monitor.synchronize do
^^^^^^^^^^^^
someone can pointing my mistake?
Hello Benoit, I'm not sure but with this I have solved this problem
def self.inherited(notifier)
notifier.const_set :Notification, Class.new(::Notification)
super
end
To answer your question Chris, would love more meta programming content. Always a topic I have to study a few times, haven't seen it yet but a series that helps people level up their meta programming game (starting from basics) would be great. Thanks for a great session here.