Implement loading settings from both, database and env variables [SCI-8813] (#5885)

This commit is contained in:
Alex Kriuchykhin 2023-08-01 10:44:27 +02:00 committed by GitHub
parent 2680b317e5
commit 4a563d3456
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View file

@ -1,4 +1,7 @@
# frozen_string_literal: true
class ApplicationSettings < Settings
def load_values_from_env
ENV.select { |name, _| name =~ /^APP_STTG_[A-Z0-9_]*/ }.transform_keys(&:downcase)
end
end

View file

@ -4,4 +4,16 @@ class Settings < ApplicationRecord
def self.instance
first || new
end
def values
merged_values = super
self.class.instance_methods(false).grep(/^load_values_from_[A-Z0-9_]*/).each do |method|
merged_values = merged_values.merge(public_send(method))
end
merged_values
end
def load_values_from_env
raise NotImplementedError
end
end