10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/active_tools/active_record/commit_and_touch.rb', line 10
def commit_and_touch(*args, &block)
options = args.
class_attribute :commit_and_touch_options unless defined?(commit_and_touch_options)
self.commit_and_touch_options ||= {}
self.commit_and_touch_options[:options] = options
self.commit_and_touch_options[:reflections] = self.reflections.keys & args.map(&:to_s)
after_commit options do
self.commit_and_touch_options[:reflections].each do |assoc|
attributes = if block_given?
block.call(self)
else
{:updated_at => Time.now}
end
send(assoc).update_all(attributes)
end
end
end
|