2013-02-20 18:09:29 +00:00
|
|
|
require "seed-fu-mongoid/version"
|
|
|
|
require "seed-fu-mongoid/document_seeder"
|
|
|
|
require "seed-fu-mongoid/seed_proxy"
|
|
|
|
require 'mongoid/document'
|
|
|
|
|
|
|
|
if defined?(Rails::Railtie)
|
|
|
|
require 'seed-fu-mongoid/railtie'
|
|
|
|
end
|
|
|
|
|
|
|
|
# punch the duck out of Mongoid::Document
|
|
|
|
|
2013-02-24 21:39:36 +00:00
|
|
|
module SeedFuMongoid
|
|
|
|
class << self
|
2014-06-04 05:31:58 +00:00
|
|
|
attr_accessor :quiet
|
|
|
|
|
2013-02-24 21:39:36 +00:00
|
|
|
def seed
|
2014-06-04 05:31:58 +00:00
|
|
|
files = Dir['db/fixtures/*.rb'].sort
|
|
|
|
files += Dir["db/fixtures/#{Rails.env}/*.rb"].sort
|
|
|
|
files.each do |file|
|
|
|
|
puts "== Seed from #{file}" unless quiet
|
2013-02-24 21:39:36 +00:00
|
|
|
|
|
|
|
load file
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-20 18:09:29 +00:00
|
|
|
module Mongoid::Document
|
|
|
|
module ClassMethods
|
2014-12-14 18:23:13 +00:00
|
|
|
def seed_once(*constraints, &block)
|
|
|
|
SeedFuMongoid::DocumentSeeder.new(self, constraints, block).seed_once!
|
2013-02-20 18:09:29 +00:00
|
|
|
end
|
|
|
|
|
2013-03-27 14:41:04 +00:00
|
|
|
def seed(*constraints_and_objects, &block)
|
|
|
|
SeedFuMongoid::DocumentSeeder.new(self, constraints_and_objects, block).seed!
|
2013-02-20 18:09:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|