seed_dump 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -4
- data/VERSION +1 -1
- data/lib/tasks/seed_dump.rake +10 -3
- data/seed_dump.gemspec +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -24,15 +24,15 @@ Result:
|
|
24
24
|
# Autogenerated by the db:seed:dump task
|
25
25
|
# Do not hesitate to tweak this to your needs
|
26
26
|
|
27
|
-
products = Product.create(
|
27
|
+
products = Product.create([
|
28
28
|
{ :category_id => 1, :description => "Long Sleeve Shirt", :name => "Long Sleeve Shirt" },
|
29
29
|
{ :category_id => 3, :description => "Plain White Tee Shirt", :name => "Plain T-Shirt" }
|
30
|
-
)
|
30
|
+
])
|
31
31
|
|
32
|
-
users = User.create(
|
32
|
+
users = User.create([
|
33
33
|
{ :id => 1, :password => "123456", :username => "test_1" },
|
34
34
|
{ :id => 2, :password => "234567", :username => "tes2" }
|
35
|
-
)
|
35
|
+
])
|
36
36
|
|
37
37
|
Append to db/seeds.rb instead of overwriting it:
|
38
38
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/tasks/seed_dump.rake
CHANGED
@@ -17,11 +17,15 @@ namespace :db do
|
|
17
17
|
|
18
18
|
new_line = "\n"
|
19
19
|
|
20
|
+
puts "Appending seeds to #{opts['file']}." if opts['append']
|
21
|
+
|
20
22
|
seed_rb = ""
|
21
|
-
Dir['app/models/*.rb'].each do |f|
|
23
|
+
Dir['app/models/*.rb'].sort.each do |f|
|
22
24
|
model_name = File.basename(f, '.*')
|
23
25
|
if models.include?(model_name) || models.empty?
|
24
26
|
|
27
|
+
puts "Adding #{model_name.camelize} seeds."
|
28
|
+
|
25
29
|
create_hash = ""
|
26
30
|
|
27
31
|
model = model_name.camelize.constantize
|
@@ -38,7 +42,6 @@ namespace :db do
|
|
38
42
|
}
|
39
43
|
|
40
44
|
create_hash << (i > 0 ? ",#{new_line}" : new_line) << indent << '{ ' << attr_s.join(', ') << ' }'
|
41
|
-
|
42
45
|
}
|
43
46
|
|
44
47
|
seed_rb << "#{new_line}#{model_name.pluralize} = #{model_name.camelize}.create([#{create_hash}#{new_line}])#{new_line}"
|
@@ -47,7 +50,9 @@ namespace :db do
|
|
47
50
|
|
48
51
|
File.open(opts['file'], (opts['append'] ? "a" : "w")) { |f|
|
49
52
|
|
50
|
-
|
53
|
+
puts "Writing #{opts['file']}."
|
54
|
+
|
55
|
+
unless opts['append']
|
51
56
|
cont =<<HERE
|
52
57
|
# Autogenerated by the db:seed:dump task
|
53
58
|
# Do not hesitate to tweak this to your needs
|
@@ -60,6 +65,8 @@ HERE
|
|
60
65
|
HERE
|
61
66
|
f << cont
|
62
67
|
|
68
|
+
puts "Done."
|
69
|
+
|
63
70
|
}
|
64
71
|
end
|
65
72
|
end
|
data/seed_dump.gemspec
CHANGED