Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adding Writer rake task and changing namespace #36

Open
wants to merge 1 commit into from

1 participant

@ready4god2513

I have added the write task inside of the seed_fu namespace to allow apps to use the writer to write their seeds via a rake task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 1, 2012
  1. Adding write task to seeds

    Brandon Hansen authored
This page is out of date. Refresh to see the latest.
Showing with 42 additions and 10 deletions.
  1. +42 −10 lib/tasks/seed_fu.rake
View
52 lib/tasks/seed_fu.rake
@@ -16,23 +16,55 @@ namespace :db do
Examples:
# default, to load all seed files for the current environment
- rake db:seed
+ rake db:seed_fu:seed
# to load seed files matching orders or customers
- rake db:seed FILTER=orders,customers
+ rake db:seed_fu:seed FILTER=orders,customers
# to load files from RAILS_ROOT/features/fixtures
- rake db:seed FIXTURE_PATH=features/fixtures
+ rake db:seed_fu:seed FIXTURE_PATH=features/fixtures
+
+ # to write seed files from RAILS_ROOT/lib/db/generators
+ rake db:seed_fu:write GENERATOR_PATH=lib/db/generators
+
+ # to write seed files from RAILS_ROOT/db/generators
+ rake db:seed_fu:write
+
+ For more information on writers see http://rubydoc.info/github/mbleigh/seed-fu/master/SeedFu/Writer
+ Note: As of 02/01/2012 the documentation for writers is incorrect. writer.write should be writer.add
+ See https://github.com/mbleigh/seed-fu/issues/32
EOS
- task :seed_fu => :environment do
- if ENV["FILTER"]
- filter = /#{ENV["FILTER"].gsub(/,/, "|")}/
- end
+
+
+ namespace :seed_fu do
+
+ task :seed => :environment do
+ if ENV["FILTER"]
+ filter = /#{ENV["FILTER"].gsub(/,/, "|")}/
+ end
+
+ if ENV["FIXTURE_PATH"]
+ fixture_paths = [ENV["FIXTURE_PATH"], ENV["FIXTURE_PATH"] + '/' + Rails.env]
+ end
- if ENV["FIXTURE_PATH"]
- fixture_paths = [ENV["FIXTURE_PATH"], ENV["FIXTURE_PATH"] + '/' + Rails.env]
+ SeedFu.seed(fixture_paths, filter)
end
+
+
+ task :write => :environment do
+ desc <<-EOS
+ Generates seeds from the database based on the generators in /db/generators
+ EOS
+
+ generator_path = ENV["GENERATOR_PATH"] || "#{Rails.root}/db/generators"
- SeedFu.seed(fixture_paths, filter)
+ Dir.foreach(generator_path) do |item|
+ next if item == "." or item == ".."
+
+ puts "Importing #{generator_path}/#{item}"
+ require File.absolute_path("#{generator_path}/#{item}")
+ end
+ end
+
end
end
Something went wrong with that request. Please try again.