ActiveSupport::Callbacksクラスメソッドで使用することは可能ですか?具体的には、以下のモジュールで、同じ状態include ActiveSupport::Callbacksを作成define_callbacksしてrun_callbacks共有するためにどこに配置しますか?
module Handler
extend ActiveSupport::Concern
# If you put it here, define_callbacks is defined but run_callbacks is not
# include ActiveSupport::Callbacks
included do
class_eval do
define_callbacks :handle
end
end
module ClassMethods
# If you put it here, run_callbacks is defined but define_callbacks is not
# include ActiveSupport::Callbacks
def handle(task)
run_callbacks :handle do
p task
end
end
end
end
class HandlerExample
include Handler
end
アップデート
可能であれば、私にはわかりませんが、それは確かActiveSupport::Callbacksに設計されたものではありません。でステートレスインスタンスオブジェクトを作成するのが最適#handleです。