Permalink
Browse files

Add /shared and /after folders, bump version

  • Loading branch information...
1 parent 44eb896 commit 1b516b75bd0640083d8a204e3c831ca768175247 @ffmike committed Aug 27, 2010
Showing with 29 additions and 8 deletions.
  1. +12 −5 README
  2. +2 −2 db_populate.gemspec
  3. +10 −0 lib/db_populate.rb
  4. +5 −1 tasks/populate.rake
View
17 README
@@ -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/production/01_users.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
@@ -72,7 +78,8 @@ the db_populate tasks available:
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
@@ -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"
View
@@ -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
@@ -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

0 comments on commit 1b516b7

Please sign in to comment.