Module: Larynx::CallbacksWithAsync::InstanceMethods
- Defined in:
- lib/larynx/callbacks_with_async.rb
Instance Method Summary collapse
- #callback_complete(callback, result) ⇒ Object
- #fire_callback(callback) ⇒ Object
-
#scope_callback(block, scope = nil) ⇒ Object
Scope takes the callback block and a method symbol which is used to return an object that scopes the block evaluation.
Instance Method Details
#callback_complete(callback, result) ⇒ Object
54 55 56 |
# File 'lib/larynx/callbacks_with_async.rb', line 54 def callback_complete(callback, result) # Override in class to handle post callback result end |
#fire_callback(callback) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/larynx/callbacks_with_async.rb', line 34 def fire_callback(callback) if @callbacks && @callbacks[callback] block, mode = *@callbacks[callback] scope = self.class.[callback][:scope] if mode == :async EM.defer(scope_callback(block, scope), lambda {|result| callback_complete(callback, result) }) else callback_complete(callback, scope_callback(block, scope).call) end else callback_complete(callback) end end |
#scope_callback(block, scope = nil) ⇒ Object
Scope takes the callback block and a method symbol which is used to return an object that scopes the block evaluation.
50 51 52 |
# File 'lib/larynx/callbacks_with_async.rb', line 50 def scope_callback(block, scope=nil) scope ? lambda { send(scope).instance_eval(&block) } : block end |