2013-11-06 14:47:26 -06:00
module SiteSettings ; end
class SiteSettings :: YamlLoader
def initialize ( file )
@file = file
end
def load
yaml = YAML . load_file ( @file )
2015-04-18 06:53:53 -05:00
yaml . each_key do | category |
2013-11-06 14:47:26 -06:00
yaml [ category ] . each do | setting_name , hash |
if hash . is_a? ( Hash )
# Get default value for the site setting:
2017-08-06 20:43:09 -05:00
value = hash . delete ( 'default' )
if value . is_a? ( Hash )
2017-08-03 13:19:02 -05:00
raise Discourse :: Deprecation , " The site setting ` #{ setting_name } ` can no longer be set based on Rails environment. See also `config/environments/<env>.rb`. "
elsif value . nil?
2017-08-15 21:42:08 -05:00
raise StandardError , " The site setting ` #{ setting_name } ` in ' #{ @file } ' is missing default value. "
2017-08-06 20:43:09 -05:00
end
2013-11-06 14:47:26 -06:00
2017-08-06 20:43:09 -05:00
if hash [ 'hidden' ] & . is_a? ( Hash )
2017-08-03 13:19:02 -05:00
raise Discourse :: Deprecation , " The site setting ` #{ setting_name } `'s hidden property can no longer be set based on Rails environment. It can only be either `true` or `false`. "
2013-11-06 14:47:26 -06:00
end
2017-08-06 20:43:09 -05:00
yield category , setting_name , value , hash . deep_symbolize_keys!
2013-11-06 14:47:26 -06:00
else
# Simplest case. site_setting_name: 'default value'
yield category , setting_name , hash , { }
end
end
end
end
2014-10-03 00:53:01 -05:00
end