|
| 1 | +seeded-generation plugin by Mark W. Foster |
| 2 | +========================================== |
| 3 | + |
| 4 | +This plugin extends any model and scaffold generators to stub individual seeds |
| 5 | +files that correspond to a model and its module directory structure. It also |
| 6 | +overrides rake db:seed so that models can be individually seeded |
| 7 | +using rake db:seed with the model name as an option. The plugin also includes |
| 8 | +a generator that just stubs seeds files for existing models. |
| 9 | + |
| 10 | +The db/seeds.rb file is updated when models are generated to require the individual |
| 11 | +model seeds files so that rake db:seed executes all the required seed files. Extended |
| 12 | +model and scaffold generators include an option --skip-seeds that blocks stubbing |
| 13 | +a seeds file for the model and an option --seeds-only that only stubs a |
| 14 | +seeds file for the model. |
| 15 | + |
| 16 | +Two default seeded generators are built as part of the install: |
| 17 | + |
| 18 | +seeded_model and seeded_scaffold. |
| 19 | + |
| 20 | +Type script/generate seeded, script/generate seeds_for, script/seeded_model or |
| 21 | +script/seeded_scaffold for more usage information. |
| 22 | + |
| 23 | +Uninstalling the plugin leaves any extended generators and the db:seed |
| 24 | +override working. To clear all plugin functionality, refer to the |
| 25 | +notes in the ../lib/seeded_generation folder after uninstalling the plugin. |
| 26 | + |
| 27 | +The plugin also installs functionality from the plugin OverrideRakeTask |
| 28 | +by Eugene Bolshakov found at: git://github.com/eugene bolshakov/override_rake_task.git |
| 29 | + |
| 30 | +and an updated version of ActiveRecord::Base.create_or_update by Michael Bleigh |
| 31 | + |
| 32 | +http://www.intridea.com/2008/2/19/activerecord-base-create_or_update-on-steroids-2?blog=company |
| 33 | + |
| 34 | +Example |
| 35 | +======= |
| 36 | + |
| 37 | +script/generate seeded my_model_generator |
| 38 | + |
| 39 | +creates a new seeded_my_model_generator generator that can then be used just like the |
| 40 | +my_model_generator generator it is based on in the following fashion: |
| 41 | + |
| 42 | +script/generate seeded_my_model_generator MyModule::MyModel |
| 43 | + |
| 44 | +creates generates all the standard model directories and stubs and includes |
| 45 | +the stub ../db/seeds/my_module/my_model_seeds.rb and adds |
| 46 | +require 'my_module/my_model_seeds' to the db/seeds.rb file. |
| 47 | + |
| 48 | +script/generate seeded_my_model_generator MyModule::MyModel --skip-seeds |
| 49 | + |
| 50 | +is just the base generator. |
| 51 | + |
| 52 | +script/generate seeded_my_model_generator MyModule::MyModel --only-seeds |
| 53 | + |
| 54 | +only adds the file ../db/seeds/my_module/my_model_seeds.rb and adds |
| 55 | +require 'my_module/my_model_seeds' to the db/seeds.rb file. |
| 56 | + |
| 57 | +This has the same functionality of the included generator seeds_for: |
| 58 | + |
| 59 | +script/generate seeds_for MyModule::MyModel |
| 60 | + |
| 61 | +which creates only a file db/seeds/my_module/my_model_seeds.rb and |
| 62 | +adds a require statement to seeds.db. |
| 63 | + |
| 64 | +rake db:seed runs all seed files required in db/seeds.rb and |
| 65 | +any other seed code there. |
| 66 | + |
| 67 | +rake db:seed MODELS=MyModule1::MyModel1, MyModule1::MyModel2 only loads seeds for the |
| 68 | +specified models if they have corresponding seeds.rb files generated. |
| 69 | + |
| 70 | +Copyright (c) 2009 Mark W. Foster, released under the MIT license |
| 71 | +fosterinfo[z]gmail.com (replace [z] with @) |
0 commit comments