settings_validator.rb revision 3e6a648aa9751228db2a82caa18f67537f049207
end
"Error in #{@key_chain.join('.')}: #{@message}"
end
end
%i(yml OMS_qualifier),
%i(yml max_read_filesize),
%i(yml exception_notifier enabled),
%i(yml git verify_url),
%i(yml git default_branch),
%i(yml git push_priority commits),
%i(yml allowed_iri_schemes),
%i(yml display_head_commit),
%i(yml display_symbols_tab),
%i(yml fallback_commit_user),
%i(yml fallback_commit_email),
%i(yml format_selection),
%i(yml formality_levels),
%i(yml license_models),
%i(yml ontology_types),
# hets.yml
%i(yml hets_owl_tools),
%i(yml stack_size),
%i(yml cmd_line_options),
%i(yml server_options),
# paths.rb
%i(initializers data_root),
%i(initializers git_home),
%i(initializers git_root),
%i(initializers symlink_path),
%i(initializers commits_path),
]
%i(initializers secret_token),
]
# paths.rb
%i(initializers data_root),
%i(initializers git_home),
%i(initializers git_root),
%i(initializers symlink_path),
%i(initializers commits_path),
]
HAS_TO_BE_URL = [
%i(yml git verify_url),
]
HAS_TO_BE_EMAIL = [
]
HAS_TO_HAVE_TYPE = {
[Array] => [
# hets.yml
],
[Fixnum] => [
# hets.yml
],
[Float] => [
],
[TrueClass, FalseClass] => [
],
}
[:validate_value_has_keys, :name, :description, :documentation],
# hets.yml
}
end
@errors = []
end
end
end
end
if @errors.present?
end
end
array.each do |value|
end
end
end
end
end
@errors << ResourceNotFound.new(key_chain,
"Executable 'hets' not found in any of the given paths: #{hets_paths}")
end
end
def get_value(key_chain)
object = base(key_chain.first)
key_chain[1..-1].each do |key|
object = object.send(key)
if object.nil?
@errors << KeyNotSet.new(key_chain, 'Key not set.')
return
end
end
object
end
def base(namespace)
if namespace == :yml
Settings
else
@config
end
end
def validate_with(key_chain, &block)
if value = get_value(key_chain)
block.call(value)
end
end
def validate_directory_exists(key_chain)
path = get_value(cfg_key_chain)
unless File.directory?(path)
@errors << NotADirectory.new(cfg_key_chain,
"Path is not a directory: #{path}")
end
end
def validate_directory_exists(key_chain)
path = get_value(cfg_key_chain)
unless File.directory?(path)
@errors << NotADirectory.new(cfg_key_chain,
"Path is not a directory: #{path}")
end
end
def validate_presence(key_chain)
validate_with(key_chain) do |value|
validate_value_is_present(key_chain, value)
end
end
def validate_type(key_chain, types)
validate_with(key_chain) do |value|
unless types.any? { |type| value.is_a?(type) }
@errors << TypeError.new(key_chain,
["Value should have as type one of #{types.join(', ')}, ",
"but has type #{value.class}."].join)
end
end
end
def validate_format_url(key_chain)
validate_with(key_chain) do |value|
unless value.match(URI.regexp)
@errors << FormatNotURL(key_chain, "Value is not a URL: #{value}")
end
end
end
def validate_format_email(key_chain)
validate_with(key_chain) do |value|
validate_value_has_format_email(key_chain, value)
end
end
def validate_value_has_keys(key_chain, value, *keys)
unless value.present? && keys.all? { |key| value[key].present? }
@errors << KeyNotSet.new(key_chain,
"Value needs to have keys: #{keys.join(', ')}")
end
end
def validate_value_has_format_email(key_chain, value)
unless value.present? && value.match(/@/)
@errors << FormatNotEmail(key_chain,
"Value is not an email address: #{value}")
end
end
def validate_value_is_present(key_chain, value)
unless value.present?
@errors << KeyNotPresent.new(key_chain, 'Value not present.')
end
end
def validate_value_is_absolute_filepath(key_chain, value)
unless value.present? && %w(/ ~/).any? { |start| value.start_with?(start) }
@errors << NotAnAbsoluteFilepath.new(key_chain,
'Has to be an absolute filepath.')
end
end
end