public
Rubygem
Description: Advanced seed data handling for Rails, combining the best practices of several methods together.
Homepage: http://mbleigh.lighthouseapp.com/projects/10223-seed-fu
Clone URL: git://github.com/mbleigh/seed-fu.git
Optionally do not overwrite seed data if it already exists. In many cases 
production servers will update data and be authoritative; therefore overwriting 
in these cases isn't what you want.

To not overwrite and just insert if not existing, use: Content.seed(:data_key, 
true) do |s|...end
darcy (author)
Mon Jul 07 15:19:59 -0700 2008
commit  a1c40c9a38dae136b76565c36c7049327f46e797
tree    d171940f87fe57172881d1f7990301240d405953
parent  93e54062cec39aad5249c4dbcc35bcaa8efcf633
...
2
3
4
 
 
5
6
7
 
8
9
10
...
26
27
28
29
 
30
 
31
32
33
...
2
3
4
5
6
7
8
 
9
10
11
12
...
28
29
30
 
31
32
33
34
35
36
0
@@ -2,9 +2,11 @@ class Seeder
0
   def self.plant(model_class, *constraints, &block)
0
     constraints = [:id] if constraints.empty?
0
     seed = Seeder.new(model_class)
0
+    insert_only = constraints.last.is_a? TrueClass
0
+    constraints.delete_at(*constraints.length-1) if (constraints.last.is_a? TrueClass or constraints.last.is_a? FalseClass)
0
     seed.set_constraints(*constraints)
0
     yield seed
0
-    seed.plant!
0
+    seed.plant!(insert_only)
0
   end
0
   
0
   def initialize(model_class)
0
@@ -26,8 +28,9 @@ class Seeder
0
     @data[name.to_sym] = value
0
   end
0
   
0
-  def plant!
0
+  def plant! insert_only=false
0
     record = get
0
+    return if !record.new_record? and insert_only
0
     @data.each do |k, v|
0
       record.send("#{k}=", v)
0
     end

Comments