11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/generators/fake/fake_generator.rb', line 11
def generate_fake
@model = table.singularize.camelize.constantize
quant = options["quant"] ? options["quant"].to_i : 1
if behavior == :invoke
total = 0
quant.times do
attributes = fake_attributes(@model)
m = @model.new
m.assign_attributes(attributes, :without_protection => true)
m.save(validate: false)
m.touch
m.save
total += 1
end
say_status "created", "Created #{total} records on the table #{table.pluralize.camelize}", :green
elsif behavior == :revoke
total = 0
@model.order('id DESC').limit(quant).each do |m|
m.destroy
total += 1
end
say_status "destroyed", "Removed #{total} records from the table #{table.pluralize.camelize}", :red
end
end
|