From: Thufir Date: 2009-09-21T13:28:21+09:00 Subject: rake task organization in the "connects" task for the following rakefile, how do I tie-in Item and Items so that there's minimal code repetition? For instance, currently Item is defined in the connect task for the rakefile, wheras I would rather that Item be "imported" either by requiring a module or including the Item.rb file, for example. What's a good approach? thufir@ARRAKIS:~/rb$ thufir@ARRAKIS:~/rb$ cat Item.rb require 'rubygems' require 'active_record' class Item < ActiveRecord::Base end thufir@ARRAKIS:~/rb$ thufir@ARRAKIS:~/rb$ cat Items.rb class Items < ActiveRecord::Migration def self.up create_table :items do |t| t.column :title, :string t.column :content, :string t.column :source, :string t.column :url, :string t.column :timestamp, :timestamp t.column :keyword_id, :integer t.column :guid, :string t.column :html, :string end end def self.down drop_table :items end end thufir@ARRAKIS:~/rb$ thufir@ARRAKIS:~/rb$ cat rakefile.rb require 'rubygems' require 'active_record' require 'feed_tools' require 'yaml' desc "connects to db" task :connect do db = YAML.load_file("database.yml") ActiveRecord::Base.establish_connection( :adapter => db["adapter"], :host => db["host"], :username => db["username"], :password => db["password"], :database => db["database"]) class Item < ActiveRecord::Base ###take out this line? end puts "connected to db" end desc "drop table items" task :drop => :connect do #drop table items puts "unable to drop table" end desc "creates table items unless exists" task :create => :connect do #create table items puts "unable to create table" end desc "populate db" task :populate => [:connect, :create] do puts "get data" end desc "clobber the db" task :clobber => [:connect, :drop, :create] do puts "clobber it!" end thufir@ARRAKIS:~/rb$ thufir@ARRAKIS:~/rb$ thanks, Thufir