Created
September 25, 2009 17:29
-
-
Save alkema/193698 to your computer and use it in GitHub Desktop.
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
task :bail do | |
hostname = `hostname`.to_s.strip | |
if hostname == 'prodsite.ca' | |
puts "this task cannot be run from this host (#{hostname})" | |
exit | |
end | |
end | |
desc "pull data from production server" | |
namespace :resources do | |
task :clobber => [:environment, :bail] do | |
class Canonical < ActiveResource::Base | |
website = "http://www.prodsite.ca/" | |
puts "#{website} user:" | |
user = STDIN.gets.chomp | |
puts "#{user}'s password:" | |
password = STDIN.gets.chomp | |
self.site = website | |
self.user = user | |
self.password = password | |
end | |
resources = %w(foos bars bazes) | |
resources.each do |resource| | |
puts resource | |
ActiveRecord::Base.connection.execute("TRUNCATE #{resource}") | |
collection = Canonical.find(:all, :from => "/#{resource}.xml") | |
collection.each {|m| | |
id = m.attributes.delete('id') | |
member = resource.classify.constantize.new(m.attributes) | |
member.id = id | |
member.save | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment