]> git.openstreetmap.org Git - rails.git/blob - config/application.rb
Instruct sprockets to recompile this file based on the settings files changing
[rails.git] / config / application.rb
1 require_relative "boot"
2
3 # Set the STATUS constant from the environment, if it matches a recognized value
4 ALLOWED_STATUS = [
5   :online,            # online and operating normally
6   :api_readonly,      # site online but API in read-only mode
7   :api_offline,       # site online but API offline
8   :database_readonly, # database and site in read-only mode
9   :database_offline,  # database offline with site in emergency mode
10   :gpx_offline        # gpx storage offline
11 ].freeze
12
13 status = if ENV["STATUS"] && ALLOWED_STATUS.include?(ENV["STATUS"].to_sym)
14            ENV["STATUS"].to_sym
15          else
16            :online
17          end
18 Object.const_set("STATUS", status)
19
20 if STATUS == :database_offline
21   require "action_controller/railtie"
22   require "action_mailer/railtie"
23   require "active_model/railtie"
24   require "sprockets/railtie"
25   require "rails/test_unit/railtie"
26 else
27   require "rails/all"
28 end
29
30 # Require the gems listed in Gemfile, including any gems
31 # you've limited to :test, :development, or :production.
32 Bundler.require(*Rails.groups)
33
34 module OpenStreetMap
35   class Application < Rails::Application
36     # Initialize configuration defaults for originally generated Rails version.
37     config.load_defaults 5.2
38
39     # Settings in config/environments/* take precedence over those specified here.
40     # Application configuration can go into files in config/initializers
41     # -- all .rb files in that directory are automatically loaded after loading
42     # the framework and any gems in your application.
43
44     # Custom directories with classes and modules you want to be autoloadable.
45     config.autoload_paths += %W[#{config.root}/lib]
46
47     # This defaults to true from rails 5.0 but our code doesn't comply
48     # with it at all so we turn it off
49     config.active_record.belongs_to_required_by_default = false
50
51     # Use SQL instead of Active Record's schema dumper when creating the database.
52     # This is necessary if your schema can't be completely dumped by the schema dumper,
53     # like if you have constraints or database-specific column types
54     config.active_record.schema_format = :sql unless STATUS == :database_offline
55
56     # Don't eager load models when the database is offline
57     config.paths["app/models"].skip_eager_load! if STATUS == :database_offline
58
59     # Use memcached for caching if required
60     config.cache_store = :mem_cache_store, Settings.memcache_servers, { :namespace => "rails:cache" } if Settings.key?(:memcache_servers)
61
62     # Use logstash for logging if required
63     if Settings.key?(:logstash_path)
64       config.logstasher.enabled = true
65       config.logstasher.suppress_app_log = false
66       config.logstasher.logger_path = Settings.logstash_path
67       config.logstasher.log_controller_parameters = true
68     end
69   end
70 end