Sha256: e50fe168d21f27a8ef5542e76ad51a0606baeea76f68bb28b0eec4c55fbccb00
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 KB
Contents
module Callbacks module ClassMethods def additional_callbacks(arr=[]) @additional_callbacks ||= arr end def callback_block(&block) @callback_block ||= (block ? block : nil) end end module InstanceMethods # Callbacks on bootstrap and configuration # Defines the callback accessors: # call_before/after_bootstrap/configure_callbacks # # When called, this method will first check to see if there # are plugins and call those plugin's callbacks when called # The method (before/after_bootstrap/configure) is called # on self if the callback method is defined on self def callback(call_time, *args, &block) self.class.callback_block.call(self, call_time) if self.class.callback_block callback_on_self(call_time, *args, &block) end def callbacks @callbacks ||= [] end private # TODO: Add docs def callback_on_self(call_time, *args, &block) if respond_to?(call_time) callbacks << call_time.to_sym case self.method(call_time).arity when 0 self.send(call_time) when 1 self.send(call_time, *args) else self.send(call_time, *args, &block) end end end end def self.included(receiver) receiver.extend ClassMethods receiver.send :include, InstanceMethods end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
auser-poolparty-1.3.0 | lib/mixins/callbacks.rb |
auser-poolparty-1.3.1 | lib/mixins/callbacks.rb |