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

Version Path
canvas_sync-0.19.0.beta1 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.18.12 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.18.10 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.18.9 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.18.8 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.18.7 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.18.6 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.18.5 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.18.3 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.18.2 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.18.1 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.18.0.beta2 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.18.0.beta1 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.43 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.42 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.41 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.40 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.39 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.38 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.37 lib/canvas_sync/class_callback_executor.rb