The Discourse class Plugin::Instance has this method:
class Plugin::Instance
def after_initialize(&block)
initializers << block
end
end
Ruby on Rails has a Active Record callback called after_initialize
The
after_initialize
callback will be called whenever an Active Record object is instantiated, either by directly usingnew
or when a record is loaded from the database. It can be useful to avoid the need to directly override your Active Recordinitialize
method.
This could be confusing to Discourse plugin developers because these two methods are unrelated. For sure, it was confusing to me; and at one time wondered why other ActiveRecord callbacks were not used in Discourse plugins, until I discovered that the Rails ActiveRecord after_initialize
callback is not related to the Discourse Plugin method after_initialize
.
The Rails callback after_initialize
is used only in ActiveRecords.
The Discourse after_initialize
method is only used in plugins and are not related to ActiveRecords.
See also: