Skip to content

Instantly share code, notes, and snippets.

@cpetschnig
Created October 25, 2012 11:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpetschnig/3952049 to your computer and use it in GitHub Desktop.
Save cpetschnig/3952049 to your computer and use it in GitHub Desktop.
Proposal for better structure of seeds in Rails engines
Engine
======
File structure:
EngineFoo
- app
- db
- seeds.rb
- lib
- seeds
- my_seeds.rb
- engine_foo.rb
engine_foo/lib/engine_foo.rb
============================
module EngineFoo
autoload :MySeeds, 'seeds/my_seeds'
end
engine_foo/lib/seeds/my_seeds.rb
================================
module EngineFoo
class MySeeds
def self.create_this_data
...
end
def self.create_that_data
...
end
def self.create
create_this_data
create_that_data
end
end
end
engine_foo/db/seeds.rb
======================
EngineFoo::MySeeds.create
HostApp
=======
host_app/db/seeds.rb
====================
# make the engine load its seed class
EngineFoo::MySeeds
# modify the seeds
class EngineFoo::MySeeds
def self.create_that_data
# modified implementation
end
end
# run the seeds
EngineFoo::Engine.load_seed
Advantages
==========
* Better structured in the engine itself
* Easily extendable
* Testable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment