Created
October 4, 2009 00:27
-
-
Save muddana/201004 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
#some script for loading models and other stuff | |
require 'rubygems' | |
require 'active_record' | |
require 'yaml' | |
#require 'app/helpers/application_helper' | |
MODEL_PATH = './app/models/' | |
LIB_PATH = './app/lib/' | |
$dbconfig = YAML::load(File.open('config/database.yml')) | |
ActiveRecord::Base.establish_connection($dbconfig["tolkin"]) | |
Dir.entries(MODEL_PATH).sort.each do |file| | |
if file!="." && file!=".." | |
require MODEL_PATH+ file | |
end | |
end | |
Dir.entries('./app/lib').sort.each do |file| | |
if file!="." && file!=".." | |
puts "Require-ing the controller file:./app/lib/"+file | |
require './app/lib/'+file | |
klass = Kernel.const_get(file[13..-4].camelize) | |
puts "Recognized the class #{file[13..-4].camelize}" | |
model_name_singular_lowercase = file[13..-4].split('_').first.downcase | |
helper_file_name = './app/helpers/'+ model_name_singular_lowercase +'_helper.rb' | |
if File.exists? helper_file_name | |
require helper_file_name | |
helper_module_name = (model_name_singular_lowercase+'_helper').camelize | |
klass.extend(Kernel.const_get(helper_module_name)) | |
puts "Extending the class to include helper: #{helper_module_name}" | |
end | |
puts "performing migration" #calls perform_migration for each of the classes | |
#klass.perform_migration(); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment