"must have value of one of the classes: #{options[:in]}"
end
end
end
rescue ::StandardError => e
error = e
end
record.errors.add attribute, 'is not a directory'
end
if error
end
end
end
'all elements must not be blank'
end
end
end
bad_uris = []
value.each do |elem|
bad_uris << elem
end
else
bad_uris << elem
end
end
end
unless bad_uris.empty?
record.errors.add(attribute,
"all elements must be valid URIs.\n"\
"The following are not:\n#{bad_uris.join("\n")}")
end
end
end
class ElementsAreEmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value.is_a?(Array) && value.all? { |elem| elem.match(/@/) }
record.errors.add attribute,
'all elements must be email addresses'
end
end
end
class ElementsHaveKeysValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
valid = value.is_a?(Array) && value.all? do |elem|
options[:keys].all? { |key| !elem[key].nil? }
end
unless valid
record.errors.add attribute,
"all elements must have those keys: #{options[:keys]}"
end
end
end
class EmailHostValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
fqdn =
if options[:hostname].respond_to?(:call)
options[:hostname].call(record)
else
options[:hostname]
end
if value.match(/@.*@/)
record.errors.add attribute,
'email address must have a valid email format.'
end
if value.include?('@') && !value.match(/@#{fqdn}\z/)
record.errors.add attribute,
"email adress must belong to the fully qualified domain name '#{fqdn}'."
end
end
end
class ExecutableValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless File.executable?(value)
record.errors.add attribute, 'must be an executable file'
end
end
end
end