seed-fu 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +12 -36
  2. data/Rakefile +1 -0
  3. data/VERSION +1 -1
  4. metadata +2 -2
data/README.rdoc CHANGED
@@ -1,27 +1,15 @@
1
1
  = Seed Fu
2
2
 
3
- Seed Fu is an attempt to once and for all solve the problem of inserting and
4
- maintaining seed data in a database. It uses a variety of techniques gathered
5
- from various places around the web and combines them to create what is
6
- hopefully the most robust seed data system around.
3
+ Seed Fu is an attempt to once and for all solve the problem of inserting and maintaining seed data in a database. It uses a variety of techniques gathered from various places around the web and combines them to create what is hopefully the most robust seed data system around.
7
4
 
8
5
 
9
6
  == Simple Usage
10
7
 
11
- Seed data is taken from the <tt>db/fixtures</tt> directory. Simply make descriptive .rb
12
- files in that directory (they can be named anything, but users.rb for the User
13
- model seed data makes sense, etc.). These scripts will be run whenever the
14
- db:seed rake task is called, and in order (you can use <tt>00_first.rb</tt>,
15
- <tt>00_second.rb</tt>, etc). You can put arbitrary Ruby code in these files,
16
- but remember that it will be executed every time the rake task is called, so
17
- it needs to be runnable multiple times on the same database.
8
+ Seed data is taken from the <tt>db/fixtures</tt> directory. Simply make descriptive .rb files in that directory (they can be named anything, but users.rb for the User model seed data makes sense, etc.). These scripts will be run whenever the <tt>db:seed</tt> (<tt>db:seed_fu</tt> for Rails 2.3.5 and greater) rake task is called, and in order (you can use <tt>00_first.rb</tt>, <tt>00_second.rb</tt>, etc). You can put arbitrary Ruby code in these files, but remember that it will be executed every time the rake task is called, so it needs to be runnable multiple times on the same database.
18
9
 
19
- You can also have environment-specific seed data placed in
20
- <tt>db/fixtures/ENVIRONMENT</tt> that will only be loaded if that is the current
21
- environment.
10
+ You can also have environment-specific seed data placed in <tt>db/fixtures/ENVIRONMENT</tt> that will only be loaded if that is the current environment.
22
11
 
23
- Let's say we want to populate a few default users. In <tt>db/fixtures/users.rb</tt> we
24
- write the following code:
12
+ Let's say we want to populate a few default users. In <tt>db/fixtures/users.rb</tt> we write the following code:
25
13
 
26
14
  User.seed(:login, :email) do |s|
27
15
  s.login = "bob"
@@ -37,13 +25,9 @@ write the following code:
37
25
  s.last_name = "Stevenson"
38
26
  end
39
27
 
40
- That's all you have to do! You will now have two users created in the system
41
- and you can change their first and last names in the users.rb file and it will
42
- be updated as such.
28
+ That's all you have to do! You will now have two users created in the system and you can change their first and last names in the users.rb file and it will be updated as such.
43
29
 
44
- The arguments passed to the <tt><ActiveRecord>.seed</tt> method are the constraining
45
- attributes: these must remain unchanged between db:seed calls to avoid data
46
- duplication. By default, seed data will constrain to the id like so:
30
+ The arguments passed to the <tt><ActiveRecord>.seed</tt> method are the constraining attributes: these must remain unchanged between db:seed calls to avoid data duplication. By default, seed data will constrain to the id like so:
47
31
 
48
32
  Category.seed do |s|
49
33
  s.id = 1
@@ -56,13 +40,11 @@ duplication. By default, seed data will constrain to the id like so:
56
40
  s.parent_id = 1
57
41
  end
58
42
 
59
- Note that any constraints that are passed in must be present in the subsequent
60
- seed data setting.
43
+ Note that any constraints that are passed in must be present in the subsequent seed data setting.
61
44
 
62
45
  == Seed-many Usage
63
46
 
64
- The default <tt>.seed` syntax is very verbose. An alternative is the `.seed_many</tt> syntax.
65
- Look at this refactoring of the first seed usage example above:
47
+ The default <tt>.seed` syntax is very verbose. An alternative is the `.seed_many</tt> syntax. Look at this refactoring of the first seed usage example above:
66
48
 
67
49
  User.seed_many(:login, :email, [
68
50
  { :login => "bob", :email => "bob@bobson.com", :first_name => "Bob", :last_name = "Bobson" },
@@ -75,19 +57,13 @@ Not as pretty, but much more concise.
75
57
 
76
58
  Seed files can be huge. To handle large files (over a million rows), try these tricks:
77
59
 
78
- * Gzip your fixtures. Seed Fu will read .rb.gz files happily. <tt>gzip -9</tt> gives the
79
- best compression, and with Seed Fu's repetitive syntax, a 160M file can shrink to 16M.
80
- * Add lines reading <tt># BREAK EVAL</tt> in your big fixtures, and Seed Fu will avoid loading
81
- the whole file into memory. If you use SeedFu::Writer, these breaks are built into
82
- your generated fixtures.
83
- * Load a single fixture with the <tt>SEED</tt> environment varialble:
84
- <tt>SEED=cities,states rake db:seed > seed_log`. Each argument to `SEED</tt> is used as a
85
- regex to filter fixtures by filename.
60
+ * Gzip your fixtures. Seed Fu will read .rb.gz files happily. <tt>gzip -9</tt> gives the best compression, and with Seed Fu's repetitive syntax, a 160M file can shrink to 16M.
61
+ * Add lines reading <tt># BREAK EVAL</tt> in your big fixtures, and Seed Fu will avoid loading the whole file into memory. If you use SeedFu::Writer, these breaks are built into your generated fixtures.
62
+ * Load a single fixture with the <tt>SEED</tt> environment variable: <tt>SEED=cities,states rake db:seed > seed_log`. Each argument to `SEED</tt> is used as a regex to filter fixtures by filename.
86
63
 
87
64
  == Generating SeedFu Files
88
65
 
89
- Say you have a CSV you need to massage and store as seed files. You can create
90
- an import script using SeedFu::Writer.
66
+ Say you have a CSV you need to massage and store as seed files. You can create an import script using SeedFu::Writer.
91
67
 
92
68
  #!/usr/bin/env ruby
93
69
  #
data/Rakefile CHANGED
@@ -14,6 +14,7 @@ begin
14
14
  gemspec.add_dependency 'rails', '>= 2.1'
15
15
  gemspec.files = FileList["[A-Z]*", "{lib,spec,rails}/**/*"] - FileList["**/*.log"]
16
16
  end
17
+ Jeweler::GemcutterTasks.new
17
18
  rescue LoadError
18
19
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
19
20
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.2.2
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seed-fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-23 00:00:00 -04:00
12
+ date: 2010-01-18 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency