Skip to content

Instantly share code, notes, and snippets.

@xeger
Created August 4, 2011 23:31
Show Gist options
  • Save xeger/1126571 to your computer and use it in GitHub Desktop.
Save xeger/1126571 to your computer and use it in GitHub Desktop.
# Send callbacks of this type after a commit.
# We push a new variable holder on each record, then pop it off, which avoids
# an infinite loop whereby an on_commit callback makes a new transaction
# (like in creating a BackgrounDRb record)
def self.callback(crud_method, &block)
record_method = @@record_methods[crud_method]
callback_method = @@callback_methods[crud_method]
committed_records = send(record_method)
unless committed_records.empty?
# ----------------- BEGIN TONY CHANGES
if(crud_method == :all)
classes_records = committed_records.group_by(&:class)
classes_records.each_pair do |klass, records|
klass.send(:banana, records) if klass.respond_to?(:banana)
end
end
# ----------------- END TONY CHANGES
committed_records.each do |record|
push
record.send(callback_method)
pop
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment