can_seed.rb 497 B

123456789101112131415161718192021222324
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module CanSeed
  3. extend ActiveSupport::Concern
  4. # methods defined here are going to extend the class, not the instance of it
  5. class_methods do
  6. def reseed
  7. destroy_all
  8. seed
  9. end
  10. def seed
  11. UserInfo.ensure_current_user_id do
  12. load seedfile
  13. end
  14. end
  15. def seedfile
  16. Rails.root.join('db', 'seeds', "#{name.pluralize.underscore.tr('/', '_')}.rb").to_s
  17. end
  18. end
  19. end