add ability to seed through code

This commit is contained in:
John Bintz 2013-02-24 16:39:36 -05:00
parent dd5b0ea9e1
commit f17f299abe
3 changed files with 16 additions and 5 deletions

View File

@ -25,3 +25,6 @@ Simple!
`require 'seed-fu-mongoid/capistrano'` to have your data get re-seeded on deploy. `require 'seed-fu-mongoid/capistrano'` to have your data get re-seeded on deploy.
### Cucumber/RSpec
`SeedFuMongoid.seed`

View File

@ -9,6 +9,18 @@ end
# punch the duck out of Mongoid::Document # punch the duck out of Mongoid::Document
module SeedFuMongoid
class << self
def seed
Dir['db/fixtures/**/*.rb'].each do |file|
puts "== Seed from #{file}"
load file
end
end
end
end
module Mongoid::Document module Mongoid::Document
module ClassMethods module ClassMethods
def seed_once(*constraints) def seed_once(*constraints)

View File

@ -4,11 +4,7 @@ module SeedFuMongoid
namespace :db do namespace :db do
desc "Load seed data from db/fixtures" desc "Load seed data from db/fixtures"
task :seed_fu => :environment do task :seed_fu => :environment do
Dir['db/fixtures/**/*.rb'].each do |file| SeedFuMongoid.seed
puts "== Seed from #{file}"
load file
end
end end
end end
end end