Skip to content

Commit

Permalink
Update to make this gem work with Rails 3.1. No longer backward
Browse files Browse the repository at this point in the history
compatible with Rails 2 or 3.0. The implementation may be mysql specific,
as one line was taken from the Mysql2 adapter.
  • Loading branch information
mpd committed Nov 21, 2011
1 parent c13c480 commit e5461f2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/acts_as_archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,26 @@ def self.included(base)
unless base.included_modules.include?(InstanceMethods)
base.send :include, InstanceMethods
base.class_eval do
unless method_defined?(:delete_sql_without_archive)
alias_method :delete_sql_without_archive, :delete_sql
alias_method :delete_sql, :delete_sql_with_archive
unless method_defined?(:delete_without_archive)
alias_method :delete_without_archive, :delete
alias_method :delete, :delete_with_archive
end
end
end
end

module InstanceMethods
def delete_sql_with_archive(sql, name = nil)
def delete_with_archive(arel, name, binds)
@mutex ||= Mutex.new
@mutex.synchronize do
unless ActsAsArchive.disabled
sql = to_sql(arel)

# Put the id into place.
# Line pulled from ActiveRecord::ConnectionAdapters::Mysql2Adapter.
# May not be compatible with other datastores.
sql = sql.gsub("\0") { quote(*(binds.dup).shift.reverse) }

from, where = /DELETE FROM (.+)/i.match(sql)[1].split(/\s+WHERE\s+/i, 2)
from = from.strip.gsub(/[`"]/, '').split(/\s*,\s*/)

Expand All @@ -216,7 +223,7 @@ def delete_sql_with_archive(sql, name = nil)
end
end

delete_sql_without_archive(sql, name)
delete_without_archive(arel, name, binds)
end
end
end
Expand Down

1 comment on commit e5461f2

@xxx
Copy link
Member

@xxx xxx commented on e5461f2 Mar 2, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have time to look into this and send a pull request, i'd be happy to merge it.

Please sign in to comment.