load_config.rb 1.68 KB
Newer Older
1 2 3
require "pathname"
require "bundler/setup"
require "configurate"
Jonne Haß's avatar
Jonne Haß committed
4

5
rails_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
6

7 8
module Rails
  def self.root
9
    @__root ||= Pathname.new File.expand_path("../../", __FILE__)
10 11
  end
end
12

13
require Rails.root.join "lib", "configuration_methods"
Jonne Haß's avatar
Jonne Haß committed
14

15
config_dir = Rails.root.join("config").to_s
Jonne Haß's avatar
Jonne Haß committed
16

17 18 19
AppConfig ||= Configurate::Settings.create do
  add_provider Configurate::Provider::Dynamic
  add_provider Configurate::Provider::Env
20 21 22 23

  unless heroku? || rails_env == "test" || File.exist?(File.join(config_dir, "diaspora.yml"))
    warn "FATAL: Configuration not found. Copy over diaspora.yml.example"
    warn "       to diaspora.yml and edit it to your needs."
Jonne Haß's avatar
Jonne Haß committed
24
    exit!
Jonne Haß's avatar
Jonne Haß committed
25
  end
26

27
  add_provider Configurate::Provider::YAML,
28
               File.join(config_dir, "diaspora.yml"),
29
               namespace: rails_env, required: false
30
  add_provider Configurate::Provider::YAML,
31
               File.join(config_dir, "diaspora.yml"),
Jonne Haß's avatar
Jonne Haß committed
32
               namespace: "configuration", required: false
33
  add_provider Configurate::Provider::YAML,
34
               File.join(config_dir, "defaults.yml"),
35
               namespace: rails_env
36
  add_provider Configurate::Provider::YAML,
37 38
               File.join(config_dir, "defaults.yml"),
               namespace: "defaults", raise_on_missing: true
39

Jonne Haß's avatar
Jonne Haß committed
40
  extend Configuration::Methods
41

Jonne Haß's avatar
Jonne Haß committed
42
  if rails_env == "production"  &&
43
     (environment.certificate_authorities.nil? ||
44 45
     environment.certificate_authorities.empty? ||
     !File.file?(environment.certificate_authorities.get))
46 47
    warn "FATAL: Diaspora doesn't know where your certificate authorities are." \
         " Please ensure they are set to a valid path in diaspora.yml"
Jonne Haß's avatar
Jonne Haß committed
48
    exit!
Jonne Haß's avatar
Jonne Haß committed
49 50
  end
end