10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/asset_cloud/callbacks.rb', line 10
def callback_methods(*symbols)
symbols.each do |method|
code = <<-"end_eval"
def self.before_#{method}(*callbacks, &block)
callbacks << block if block_given?
write_inheritable_array(:before_#{method}, callbacks)
end
def self.after_#{method}(*callbacks, &block)
callbacks << block if block_given?
write_inheritable_array(:after_#{method}, callbacks)
end
def #{method}_with_callbacks(*args)
if execute_callbacks(:before_#{method}, args)
result = #{method}_without_callbacks(*args)
execute_callbacks(:after_#{method}, args)
end
result
end
alias_method_chain :#{method}, 'callbacks'
end_eval
self.class_eval code, __FILE__, __LINE__
end
end
|