config: make danbooru_local_config.rb optional.
Make it so that if danbooru_local_config.rb doesn't exist, we continue with the default config instead of failing.
This commit is contained in:
@@ -14,10 +14,22 @@ require "rails/test_unit/railtie"
|
||||
|
||||
Bundler.require(*Rails.groups)
|
||||
|
||||
require_relative "danbooru_default_config"
|
||||
require_relative "danbooru_local_config"
|
||||
begin
|
||||
require_relative "danbooru_default_config"
|
||||
require_relative "danbooru_local_config"
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
module Danbooru
|
||||
mattr_accessor :config
|
||||
|
||||
# if danbooru_local_config exists then use it as the config, otherwise use danbooru_default_config.
|
||||
if defined?(CustomConfiguration)
|
||||
self.config = EnvironmentConfiguration.new(CustomConfiguration.new)
|
||||
else
|
||||
self.config = EnvironmentConfiguration.new(Configuration.new)
|
||||
end
|
||||
|
||||
class Application < Rails::Application
|
||||
# Use the responders controller from the responders gem
|
||||
config.app_generators.scaffold_controller :responders_controller
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
module Danbooru
|
||||
module_function
|
||||
|
||||
class Configuration
|
||||
# A secret key used to encrypt session cookies, among other things. If this
|
||||
# token is changed, existing login sessions will become invalid. If this
|
||||
@@ -469,19 +467,11 @@ module Danbooru
|
||||
end
|
||||
end
|
||||
|
||||
class EnvironmentConfiguration
|
||||
def custom_configuration
|
||||
@custom_configuration ||= CustomConfiguration.new
|
||||
end
|
||||
|
||||
EnvironmentConfiguration = Struct.new(:config) do
|
||||
def method_missing(method, *args)
|
||||
var = ENV["DANBOORU_#{method.to_s.upcase.chomp("?")}"]
|
||||
|
||||
var.presence || custom_configuration.send(method, *args)
|
||||
var.presence || config.send(method, *args)
|
||||
end
|
||||
end
|
||||
|
||||
def config
|
||||
@config ||= EnvironmentConfiguration.new
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user