Class: ActiveModelCachers::ActiveRecord::ClassCallbacks

Inherits:
Object
  • Object
show all
Defined in:
lib/active_model_cachers/active_record/global_callbacks.rb

Instance Method Summary collapse

Constructor Details

#initializeClassCallbacks

Returns a new instance of ClassCallbacks.



50
51
52
# File 'lib/active_model_cachers/active_record/global_callbacks.rb', line 50

def initialize
  @class_callbacks = Hash.new{|h, k| h[k] = [] }
end

Instance Method Details

#add_callback(class_name, &block) ⇒ Object



58
59
60
# File 'lib/active_model_cachers/active_record/global_callbacks.rb', line 58

def add_callback(class_name, &block)
  callbacks_at(class_name) << block
end

#callbacks_at(class_name) ⇒ Object



54
55
56
# File 'lib/active_model_cachers/active_record/global_callbacks.rb', line 54

def callbacks_at(class_name)
  @class_callbacks[class_name]
end

#exec(scope, klass, *args) ⇒ Object



62
63
64
# File 'lib/active_model_cachers/active_record/global_callbacks.rb', line 62

def exec(scope, klass, *args)
  callbacks_at(klass.name).each{|s| scope.instance_exec(*args, &s) }
end