Skip to content

Instantly share code, notes, and snippets.

@bryanstearns
Created July 7, 2010 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanstearns/466192 to your computer and use it in GitHub Desktop.
Save bryanstearns/466192 to your computer and use it in GitHub Desktop.
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