gemfile_helper.rb 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. class GemfileHelper
  2. class << self
  3. def load_dotenv
  4. dotenv_dir = Dir[File.join(File.dirname(__FILE__), '../vendor/gems/dotenv-[0-9]*')].sort.last
  5. yield dotenv_dir
  6. return if ENV['ON_HEROKU'] == 'true'
  7. $:.unshift File.join(dotenv_dir, 'lib')
  8. require "dotenv"
  9. $:.shift
  10. root = Pathname.new(File.join(File.dirname(__FILE__), '..'))
  11. sanity_check Dotenv.load(
  12. root.join(".env.local"),
  13. root.join(".env.#{ENV['RAILS_ENV'] || 'development'}"),
  14. root.join(".env")
  15. )
  16. end
  17. private
  18. def sanity_check(env)
  19. return if ENV['CI'] == 'true' || !env.empty?
  20. puts warning
  21. raise "Could not load huginn settings from .env file."
  22. end
  23. def warning
  24. <<-EOF
  25. Could not load huginn settings from .env file.
  26. Make sure to copy the .env.example to .env and change it to match your configuration.
  27. Capistrano 2 users: Make sure shared files are symlinked before bundle runs: before 'bundle:install', 'deploy:symlink_configs'
  28. EOF
  29. end
  30. end
  31. end