gemfile_helper.rb 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. $:.unshift File.join(dotenv_dir, 'lib')
  7. require "dotenv"
  8. $:.shift
  9. root = Pathname.new(File.join(File.dirname(__FILE__), '..'))
  10. sanity_check Dotenv.load(
  11. root.join(".env.local"),
  12. root.join(".env.#{ENV['RAILS_ENV']}"),
  13. root.join(".env")
  14. )
  15. end
  16. private
  17. def sanity_check(env)
  18. return if ENV['CI'] == 'true' || !env.empty?
  19. puts warning
  20. raise "Could not load huginn settings from .env file."
  21. end
  22. def warning
  23. <<-EOF
  24. Could not load huginn settings from .env file.
  25. Make sure to copy the .env.example to .env and change it to match your configuration.
  26. Capistrano 2 users: Make sure shared files are symlinked before bundle runs: before 'bundle:install', 'deploy:symlink_configs'
  27. EOF
  28. end
  29. end
  30. end