Created
July 7, 2010 01:57
-
-
Save bryanstearns/466192 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ManualUpdate | |
def self.by(login_name) | |
ActiveRecord::Base.transaction do | |
ActiveRecord::Base.current_user = User.find_by_login!(login_name) | |
PaperTrail.whodunnit = login_name | |
puts "Running update..." | |
yield | |
puts "Checking database validity..." | |
site = "local" if Rails.env.development? | |
unless Checker.check(:verbose => ENV["VERBOSE"], | |
:site => site) | |
puts "Check failed... rolling back." | |
raise ActiveRecord::Rollback | |
end | |
if ENV["DRY_RUN"] | |
# note: DRY_RUN=1 must come before "ruby" on the command line! | |
puts "Check passed, but DRY_RUN specified... rolling back." | |
raise ActiveRecord::Rollback | |
end | |
puts "Check passed ... committed." | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment