Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alkema/193698 to your computer and use it in GitHub Desktop.
Save alkema/193698 to your computer and use it in GitHub Desktop.
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