Add /shared and /after folders, bump version

This commit is contained in:
Mike Gunderloy 2010-08-27 15:08:27 -05:00
parent 44eb896624
commit 1b516b75bd
4 changed files with 29 additions and 8 deletions

13
README
View File

@ -26,13 +26,19 @@ To get started with db_populate, create the folder db/populate in your Rails app
Any code you put in this folder will be run by db_populate. Optionally, you can create
subfolders for your Rails environments, just as you can with config files. db_populate
executes all of the top-level populate files first, followed by any environment-specific
populate files, sorting each list by name. So, for example, with 4 files in the production
environment, db_populate would order this way:
populate files, sorting each list by name.
Files in the 'shared' subfolder will be run for all environments, sorted with the other
files for that environment. Files in the 'after' subfolder will be run after any environment.
So, for example, with 6 files in the production environment, db_populate would order this way:
db/populate/01_roles.rb
db/populate/02_services.rb
db/populate/production/01_users.rb
db/populate/production/02_options.rb
db/populate/shared/02_options.db
db/populate/production/03_accounts.rb
db/populate/after/01_cleanup.rb
Within each file, you can place whatever ruby code you like. To help create consistent
records, db_populate adds create_or_update to ActiveRecord::Base. This method looks up
@ -73,6 +79,7 @@ require 'db_populate'
History
=======
2010-08-27 Added /shared and /after conventions
2009-11-26 Allow create_or_update to skip validations (suggestion by Josh Sharpe)
2009-11-26 Fix gem version (bug reported by Vitaly Ignatov)
2009-09-15 Add db:reset_and_populate task

View File

@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = "db_populate"
s.version = "0.2.5"
s.date = "2009-11-26"
s.version = "0.2.6"
s.date = "2010-08-27"
s.summary = "Seed data populator for Rails"
s.email = "MikeG1@larkfarm.com"
s.homepage = "http://github.com/ffmike/db-populate/tree/master"

10
lib/db_populate.rb Normal file
View File

@ -0,0 +1,10 @@
require 'rake'
module DbPopulate
DBP_ROOT = File.dirname(__FILE__)
end
# prevent the task from being loaded multiple times.
unless Rake::Task.task_defined? "db:populate"
# Load the rakefile so users of the gem get the tasks
load File.join(DbPopulate::DBP_ROOT, '..', 'tasks', 'populate.rake')
end

View File

@ -7,7 +7,11 @@ namespace :db do
load fixture
puts "Loaded #{fixture}"
end
Dir[File.join(RAILS_ROOT, 'db', 'populate', RAILS_ENV, '*.rb')].sort.each do |fixture|
(Dir[File.join(RAILS_ROOT, 'db', 'populate', RAILS_ENV, '*.rb')] + Dir[File.join(RAILS_ROOT, 'db', 'populate', 'shared', '*.rb')]).sort{|x,y| File.basename(x) <=> File.basename(y)}.each do |fixture|
load fixture
puts "Loaded #{fixture}"
end
Dir[File.join(RAILS_ROOT, 'db', 'populate', 'after', '*.rb')].sort.each do |fixture|
load fixture
puts "Loaded #{fixture}"
end