CONFIG_INITIALIZER_FILES = "config/environments/#{Rails.env}[.local].rb"
exit 1
end
end
end
end
if category == :initializers
"#{format_initializer_error(key_portions)} #{format_key(key_portions)}"
else
end
<<-MESSAGE
#{opening_line}:
#{format_messages(messages)}
Value: #{bad_value.inspect}
MESSAGE
end
def key_info(key)
category, *portions = key.to_s.split('__')
[category.to_sym, portions]
end
def format_key(portions)
portions.join('.')
end
def format_messages(messages)
messages.map { |message| format_message(message) }.join("\n")
end
def format_message(message)
if message == 'is not included in the list'
message =
"#{message} (see the comments in the config/settings.yml at this key)"
end
indent_message(message, 2)
end
def format_initializer_error(key_portions)
key = key_portions.join('.')
if 'fqdn' == key
"The FQDN could not be determined. Please set the hostname in #{CONFIG_YML_FILES}"
elsif %w(data_root git_root git_daemon_path git_ssh_path commits_path).include?(key)
'Please check the paths keys in the settings -'
else
# other possible values: %w(consider_all_requests_local secret_token log_level)
"Please set a valid value in the #{CONFIG_INITIALIZER_FILES} for"
end
end
def value_of(category, key_portions)
if !%i(yml initializers).include?(category)
SettingsValidationWrapper.new.send(category)
else
object = SettingsValidationWrapper.base(category.to_s)
SettingsValidationWrapper.get_value(object, key_portions)
end
end
def indent_message(message, indentation)
message.split("\n").map { |line| "#{' ' * indentation}#{line}"}.join("\n")
end
end