discourse/lib/site_settings/yaml_loader.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
1.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
module SiteSettings; end
class SiteSettings::YamlLoader
def initialize(file)
@file = file
end
def load
yaml = YAML.load_file(@file)
yaml.each_key do |category|
yaml[category].each do |setting_name, hash|
if hash.is_a?(Hash)
# Get default value for the site setting:
value = hash.delete('default')
2018-11-14 02:03:02 -05:00
if value.nil?
raise StandardError, "The site setting `#{setting_name}` in '#{@file}' is missing default value."
end
if hash.values_at('min', 'max').any? && hash['validator'].present?
raise StandardError, "The site setting `#{setting_name}` in '#{@file}' will have it's min/max validation ignored because there is a validator also specified."
end
yield category, setting_name, value, hash.deep_symbolize_keys!
else
# Simplest case. site_setting_name: 'default value'
yield category, setting_name, hash, {}
end
end
end
end
end