Last Updated: February 25, 2016
·
688
· fgimenez

factorizing seedbank

I've recently meet seedbank https://github.com/james2m/seedbank, a great gem to keep your seeds organized. I tried to give them even more structure, factorizing some common functionalities into methods, but had some troubles with scopes. Here is a quick and simple solution:

# db/seeds/myapp_common.seeds.rb

module ::MyAppSeeds
  def self.my_common_functionality(arg1)
    ...
  end
end

# db/seeds/mymodel.seeds.rb

after :myapp_common do
  ...
  ::MyAppSeeds.my_common_functionality('foo')
  ...
end