Sha256: 131003eae9b93b8cf2eadbc758101efd2ce9afeaa26363ee325795f0abcdf75e
Contents?: true
Size: 852 Bytes
Versions: 135
Compression:
Stored size: 852 Bytes
Contents
module CanvasSync # Helper/Hack class to allow calling ActiveSupport callbacks on a class instead of just on instances class ClassCallbackExecutor include ActiveSupport::Callbacks attr_reader :callback_class delegate :__callbacks, to: :callback_class delegate_missing_to :callback_class def initialize(cls, env) @callback_class = cls env.keys.each do |k| define_singleton_method(k) do env[k] end end end def clazz callback_class end def self.run_callbacks(cls, callback, env={}, &blk) new(cls, env).run_callbacks(callback, &blk) end def self.run_if_defined(cls, callback, *args, &blk) if cls.respond_to?(:"_#{callback}_callbacks") run_callbacks(cls, callback, *args, &blk) else blk.call end end end end
Version data entries
135 entries across 135 versions & 1 rubygems