From aa9d34a3f08f289c760f372034c2feb6f9be36fd Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 5 Jun 2020 15:49:51 -0500 Subject: [PATCH] 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. --- config/application.rb | 16 ++++++++++++++-- config/danbooru_default_config.rb | 14 ++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/config/application.rb b/config/application.rb index c8a3373fc..28d80a21f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index 516533b0f..c3f22f050 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -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