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.17.23.beta1 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.20 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.19 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.18 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.17.beta1 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.16 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.15 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.14 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.13 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.12 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.10.beta2 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.10.beta1 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.8 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.8.beta4 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.8.beta3 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.8.beta2 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.8.beta1 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.7 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.7.beta1 lib/canvas_sync/class_callback_executor.rb
canvas_sync-0.17.6 lib/canvas_sync/class_callback_executor.rb