# frozen_string_literal: true # # The System configuration. Various configuration items that can be updated/defined at run time # # Use of this class allows you to simply ask for the configuration parameter directly without # first having to get an instance of it. # # SystemConfiguration.queue_impl #=> 'RedisQueue' # # This method only is allowed for accessors, you should NEVER set values on the SystemConfiguration # unless you are updating via the Admin or Stack UI, or during testing to setup a specific configuration # for that. # module CoreSystemConfiguration extend ActiveSupport::Concern def self.included(base) base.class_eval do attr_accessor :configuration # # Fields # field :environment, type: String, default: 'test' field :fips_mode, type: Boolean, default: false field :fav_icon_path, { type: String, default: '/favicon.ico' } field :stack_logo_path, { type: String, default: 'ui-company-logo.png' } field :primary_stylesheet, { type: String, default: 'app47' } field :short_cache, { type: Integer, default: 1 } field :medium_cache, { type: Integer, default: 5 } field :long_cache, { type: Integer, default: 15 } # URLs field :base_url, type: String field :cdn_url, type: String field :asset_cdn_url, type: String # Time Zone Support field :default_time_zone, type: String, default: 'US/Eastern' # TTLs field :user_model_audit_log_ttl, type: Integer, default: 365 # # Validations # validates :environment, presence: true, uniqueness: true validates :default_time_zone, presence: true end base.extend ClassMethods end # # Class methods for SystemConfiguration # module ClassMethods def configuration SystemConfiguration.find_or_create_by!(environment: Rails.env) end # # NOTE: Currently ignored Codacy issue: When using 'method_missing', fall back on 'super' # def method_missing(method, *args, &block) if configuration.respond_to?(method) configuration.send(method, *args, &block) else super end end def respond_to?(method_name, include_private = false) super || configuration.respond_to?(method_name, include_private) end def respond_to_missing?(method_name, include_private = false) configuration.respond_to?(method_name, include_private) || super end end # # Cache times in minutes # def short_cache_time short_cache.minutes end def medium_cache_time medium_cache.minutes end def long_cache_time long_cache.minutes end end