Sha256: 75df15f00d736fcb12c221dceaf763cb761d105839df0a7d625248362226b35b
Contents?: true
Size: 925 Bytes
Versions: 9
Compression:
Stored size: 925 Bytes
Contents
module CanTango::Ability module Callbacks include CanTango::Helpers::Debug def self.included(base) base.extend ClassMethods end module ClassMethods [:after, :before].each do |type| class_eval %{ def #{type}_execute_callbacks @#{type}_execute_callbacks ||= [] end def #{type}_execute *callbacks @#{type}_execute_callbacks = callbacks.flatten end } end end # should execute :after_execute callbacks def handle_callbacks type callbacks_method = "#{type}_execute_callbacks" raise ArgumentError, "Not a valid callback type: #{type}" if !self.class.respond_to? callbacks_method self.class.send(callbacks_method).each {|callback| send(callback) } end def within_callbacks &block handle_callbacks :before yield handle_callbacks :after end end end
Version data entries
9 entries across 9 versions & 1 rubygems