seeder.rb 894 B

1234567891011121314151617181920212223
  1. class Seeder
  2. def self.seed
  3. if User.any?
  4. puts "At least one User already exists, not seeding."
  5. exit
  6. end
  7. user = User.find_or_initialize_by(:email => ENV['SEED_EMAIL'].presence || "admin@example.com")
  8. user.username = ENV['SEED_USERNAME'].presence || "admin"
  9. user.password = ENV['SEED_PASSWORD'].presence || "password"
  10. user.password_confirmation = ENV['SEED_PASSWORD'].presence || "password"
  11. user.invitation_code = User::INVITATION_CODES.first
  12. user.admin = true
  13. user.save!
  14. if DefaultScenarioImporter.seed(user)
  15. puts "NOTE: The example 'SF Weather Agent' will not work until you edit it and put in a free API key from http://www.wunderground.com/weather/api/"
  16. puts "See the Huginn Wiki for more Agent examples! https://github.com/huginn/huginn/wiki"
  17. else
  18. raise('Unable to import the default scenario')
  19. end
  20. end
  21. end