4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/seed_dump/environment.rb', line 4
def dump_using_environment(env = {})
Rails.application.eager_load!
models = if env['MODEL'] || env['MODELS']
(env['MODEL'] || env['MODELS']).split(',').collect {|x| x.strip.underscore.singularize.camelize.constantize }
else
ActiveRecord::Base.descendants.select do |model|
(model.to_s != 'ActiveRecord::SchemaMigration') && \
model.table_exists? && \
model.exists?
end
end
append = (env['APPEND'] == 'true')
models.each do |model|
model = model.limit(env['LIMIT'].to_i) if env['LIMIT']
SeedDump.dump(model,
append: append,
batch_size: (env['BATCH_SIZE'] ? env['BATCH_SIZE'].to_i : nil),
exclude: (env['EXCLUDE'] ? env['EXCLUDE'].split(',').map {|e| e.strip.to_sym} : nil),
file: (env['FILE'] || 'db/seeds.rb'))
append = true
end
end
|