From 1b516b75bd0640083d8a204e3c831ca768175247 Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Fri, 27 Aug 2010 15:08:27 -0500 Subject: [PATCH] Add /shared and /after folders, bump version --- README | 17 ++++++++++++----- db_populate.gemspec | 4 ++-- lib/db_populate.rb | 10 ++++++++++ tasks/populate.rake | 6 +++++- 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 lib/db_populate.rb diff --git a/README b/README index 139ea30..b31e782 100644 --- a/README +++ b/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 diff --git a/db_populate.gemspec b/db_populate.gemspec index f0a8966..bffdc39 100644 --- a/db_populate.gemspec +++ b/db_populate.gemspec @@ -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" diff --git a/lib/db_populate.rb b/lib/db_populate.rb new file mode 100644 index 0000000..ea8b888 --- /dev/null +++ b/lib/db_populate.rb @@ -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 diff --git a/tasks/populate.rake b/tasks/populate.rake index a94235b..53125c7 100644 --- a/tasks/populate.rake +++ b/tasks/populate.rake @@ -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