I have a Ruby on Rails application (ruby 1.8.7 ; rails 2.3.18). I have a customised rake task (basically a ruby program) which compares two arrays, and then stores their difference in a third array (arr3 = arr1 - arr2). In the application there is a user model. And I have a database script that suspends (deletes) users from the model/db. So I want to call this database script from the rake task after the arr3
is created. I want to run this script until all the elements in arr3
are deleted. The arrays give the difference between two lists of users.
Can anyone guide me on this? How can I call a database script from a rake task? Anything on this will be of great help.
The rake file is as below:
namespace :db do
arr1 = Array.new
arr2 = Array.new
arr3 = Array.new
desc "load data from csv"
task :load_is_data do
require 'fastercsv'
CSV.foreach("C:/Sites/rails_project/demo_app/list1.csv") do |row|
arr1 << row[0]
end
CSV.foreach("C:/Sites/rails_project/demo_app/list2.csv") do |row|
arr2 << row[0]
end
arr3 = arr1-arr2
puts "Inactive: #{arr3}"
#CODE TO BE ADDED, TO CALL DATABASE-SCRIPT
end
end
Thanks, Bhargav