Class: CanvasSync::ClassCallbackExecutor
- Inherits:
-
Object
- Object
- CanvasSync::ClassCallbackExecutor
- Includes:
- ActiveSupport::Callbacks
- Defined in:
- lib/canvas_sync/class_callback_executor.rb
Overview
Helper/Hack class to allow calling ActiveSupport callbacks on a class instead of just on instances
Instance Attribute Summary collapse
-
#callback_class ⇒ Object
readonly
Returns the value of attribute callback_class.
Class Method Summary collapse
- .run_callbacks(cls, callback, env = {}, &blk) ⇒ Object
- .run_if_defined(cls, callback, *args, &blk) ⇒ Object
Instance Method Summary collapse
- #clazz ⇒ Object
-
#initialize(cls, env) ⇒ ClassCallbackExecutor
constructor
A new instance of ClassCallbackExecutor.
Constructor Details
#initialize(cls, env) ⇒ ClassCallbackExecutor
Returns a new instance of ClassCallbackExecutor.
10 11 12 13 14 15 16 17 |
# File 'lib/canvas_sync/class_callback_executor.rb', line 10 def initialize(cls, env) @callback_class = cls env.keys.each do |k| define_singleton_method(k) do env[k] end end end |
Instance Attribute Details
#callback_class ⇒ Object (readonly)
Returns the value of attribute callback_class.
6 7 8 |
# File 'lib/canvas_sync/class_callback_executor.rb', line 6 def callback_class @callback_class end |
Class Method Details
.run_callbacks(cls, callback, env = {}, &blk) ⇒ Object
23 24 25 |
# File 'lib/canvas_sync/class_callback_executor.rb', line 23 def self.run_callbacks(cls, callback, env={}, &blk) new(cls, env).run_callbacks(callback, &blk) end |
.run_if_defined(cls, callback, *args, &blk) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/canvas_sync/class_callback_executor.rb', line 27 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 |
Instance Method Details
#clazz ⇒ Object
19 20 21 |
# File 'lib/canvas_sync/class_callback_executor.rb', line 19 def clazz callback_class end |