hasmanythrough.com) for the preceding code.
The following script is a modification of the previous program that works with any
Active Record models, even outside of a Ruby on Rails program. It will work on a Ruby on Rails
program as well, given the correct arguments. It assumes that you have a YAML file to hold the
database connection parameters, with the following format:
CHAPTER 8 ?– ACTIVE RECORD AND THE REAL WORLD 211
database:
adapter: mysql
host: localhost
username: myuser
password: mypass
database: db1
The first argument is the path to the YAML configuration file; the second is the configuration
root, in this case, database; and the remaining arguments are the paths to one or more
Active Record models you??™d like to validate:
require "rubygems"
require_gem "activerecord"
config_file = ARGV.shift
environment = ARGV.shift
@config = YAML.load_file(config_file)
ARGV.each { |file| puts file; require file }
Object.subclasses_of(ActiveRecord::Base).select { |c|
c.base_class == c}.sort_by(&:name).each do |klass|
klass.
Pages:
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481