Module: ActiveModelCachers::Hook::OnModelDelete::ClassMethods

Defined in:
lib/active_model_cachers/hook/on_model_delete.rb

Instance Method Summary collapse

Instance Method Details

#after_delete(&callback) ⇒ Object


23
24
25
# File 'lib/active_model_cachers/hook/on_model_delete.rb', line 23

def after_delete(&callback)
  after_delete_hooks << callback
end

#after_delete_hooksObject


31
32
33
# File 'lib/active_model_cachers/hook/on_model_delete.rb', line 31

def after_delete_hooks
  @after_delete_hooks ||= []
end

#before_delete(&callback) ⇒ Object


19
20
21
# File 'lib/active_model_cachers/hook/on_model_delete.rb', line 19

def before_delete(&callback)
  before_delete_hooks << callback
end

#before_delete_hooksObject


27
28
29
# File 'lib/active_model_cachers/hook/on_model_delete.rb', line 27

def before_delete_hooks
  @before_delete_hooks ||= []
end

#delete(id, model = nil) ⇒ Object


35
36
37
38
39
40
# File 'lib/active_model_cachers/hook/on_model_delete.rb', line 35

def delete(id, model = nil)
  before_delete_hooks.each{|s| s.call(id, model) }
  result = super(id)
  after_delete_hooks.each{|s| s.call(id, model) }
  return result
end

#nullify_hooks_at(column) ⇒ Object


42
43
44
45
# File 'lib/active_model_cachers/hook/on_model_delete.rb', line 42

def nullify_hooks_at(column)
  @nullify_hooks ||= Hash.new{|h, k| h[k] = [] }
  return @nullify_hooks[column]
end

#on_nullify(column, &callback) ⇒ Object


47
48
49
# File 'lib/active_model_cachers/hook/on_model_delete.rb', line 47

def on_nullify(column, &callback)
  nullify_hooks_at(column) << callback
end

#prepend_before_delete(&callback) ⇒ Object


15
16
17
# File 'lib/active_model_cachers/hook/on_model_delete.rb', line 15

def prepend_before_delete(&callback)
  before_delete_hooks.unshift(callback)
end