class DaFunk::NotificationCallback
Constants
- CallbackResult
Attributes
after[R]
before[R]
description[R]
on[R]
results[RW]
Public Class Methods
new(description, procs = {})
click to toggle source
# File lib/da_funk/notification_callback.rb, line 8 def initialize(description, procs = {}) @description = description @on = procs[:on] @before = procs[:before] @after = procs[:after] @results = {:on => [], :before => [], :after => []} schedule! end
Public Instance Methods
call(event, moment = :on)
click to toggle source
# File lib/da_funk/notification_callback.rb, line 21 def call(event, moment = :on) if support?(moment) results[moment] << CallbackResult.call( Time.now, perform(event, moment), Time.now ) end end
schedule!()
click to toggle source
# File lib/da_funk/notification_callback.rb, line 17 def schedule! Notification.schedule(self) end
Private Instance Methods
equal_arity?(event, moment)
click to toggle source
# File lib/da_funk/notification_callback.rb, line 43 def equal_arity?(event, moment) send(moment).arity == event.parameters.size end
perform(event, moment)
click to toggle source
# File lib/da_funk/notification_callback.rb, line 32 def perform(event, moment) unless equal_arity?(event, moment) return "Error Arity not Match: Event arity #{event.parameters.size} Proc arity #{send(moment).arity}" end self.send(moment).call(*event.parameters) end
support?(moment)
click to toggle source
# File lib/da_funk/notification_callback.rb, line 39 def support?(moment) ! send(moment).nil? end