diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-25 03:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-25 03:08:36 +0300 |
commit | 15e5a05bcd3525dd6c046dca2682b04532ba9bd1 (patch) | |
tree | d7336c9eab9716f541eb9548d51d4c59ff34aa3c /lib/gitlab_settings/settings.rb | |
parent | 3d911c6c1f34df47036f1d7e0838e4d5876ee923 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab_settings/settings.rb')
-rw-r--r-- | lib/gitlab_settings/settings.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/gitlab_settings/settings.rb b/lib/gitlab_settings/settings.rb new file mode 100644 index 00000000000..79d006fb118 --- /dev/null +++ b/lib/gitlab_settings/settings.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module GitlabSettings + class Settings + attr_reader :source + + def initialize(source, section) + raise(ArgumentError, 'config source is required') if source.blank? + raise(ArgumentError, 'config section is required') if section.blank? + + @source = source + @section = section + + reload! + end + + def reload! + yaml = ActiveSupport::ConfigurationFile.parse(source) + all_configs = yaml.deep_stringify_keys + configs = all_configs[section] + + @config = Options.build(configs) + end + + def method_missing(name, *args) + config.public_send(name, *args) # rubocop: disable GitlabSecurity/PublicSend + end + + def respond_to_missing?(name, include_all = false) + config.respond_to?(name, include_all) + end + + private + + attr_reader :config, :section + end +end |