Created
November 24, 2011 16:51
-
-
Save code-later/1391787 to your computer and use it in GitHub Desktop.
Apply arbitrary changes to a bunch of ActiveRecord entities
This file contains 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
changes = { | |
"Boooking:234" => lambda { |record| record.some_attribute = "new_value" } | |
} | |
changes.each do |model_class_and_id, change| | |
begin | |
klass = model_class_and_id.split(":").first.constantize | |
id = model_class_and_id.split(":").last.to_i | |
print "== Changing #{klass} '#{id}' ... " | |
record = klass.find(id) | |
change.call(record) | |
print "Changes were: #{record.changes.inspect} " | |
if ENV["SAVE"] | |
record.save(false) | |
print "[DONE]" | |
end | |
rescue => e | |
print "[FAILED] (#{e.message})" | |
end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment