687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa class ClassValidator < ActiveModel::EachValidator
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa "must have value of one of the classes: #{options[:in]}"
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa class DirectoryValidator < ActiveModel::EachValidator
35846855311c07295957e6bae381aa5c07392de2Eugen Kuksa Dir.chdir(Rails.root) { value = Pathname.new(value).expand_path }
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa record.errors.add attribute, 'is not a directory'
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa class ElementsArePresentValidator < ActiveModel::EachValidator
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa unless value.is_a?(Array) && value.all? { |elem| elem.present? }
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa class ElementsAreUrisValidator < ActiveModel::EachValidator
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa bad_uris << elem
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa unless bad_uris.empty?
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa record.errors.add(attribute,
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa "all elements must be valid URIs.\n"\
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa "The following are not:\n#{bad_uris.join("\n")}")
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa class ElementsAreEmailValidator < ActiveModel::EachValidator
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa def validate_each(record, attribute, value)
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa unless value.is_a?(Array) && value.all? { |elem| elem.match(/@/) }
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa record.errors.add attribute,
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa 'all elements must be email addresses'
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa class ElementsHaveKeysValidator < ActiveModel::EachValidator
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa def validate_each(record, attribute, value)
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa valid = value.is_a?(Array) && value.all? do |elem|
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa options[:keys].all? { |key| !elem[key].nil? }
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa unless valid
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa record.errors.add attribute,
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa "all elements must have those keys: #{options[:keys]}"
87a46b6e4db760590780a339528decb20e0c2d8bEugen Kuksa class EmailHostValidator < ActiveModel::EachValidator
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa def validate_each(record, attribute, value)
8acd979bfae73bf7f16f0f4ea1f3310cf14d2078Eugen Kuksa if options[:hostname].respond_to?(:call)
8acd979bfae73bf7f16f0f4ea1f3310cf14d2078Eugen Kuksa options[:hostname].call(record)
8acd979bfae73bf7f16f0f4ea1f3310cf14d2078Eugen Kuksa options[:hostname]
87a46b6e4db760590780a339528decb20e0c2d8bEugen Kuksa if value.match(/@.*@/)
87a46b6e4db760590780a339528decb20e0c2d8bEugen Kuksa record.errors.add attribute,
87a46b6e4db760590780a339528decb20e0c2d8bEugen Kuksa 'email address must have a valid email format.'
87a46b6e4db760590780a339528decb20e0c2d8bEugen Kuksa if value.include?('@') && !value.match(/@#{fqdn}\z/)
8acd979bfae73bf7f16f0f4ea1f3310cf14d2078Eugen Kuksa record.errors.add attribute,
8acd979bfae73bf7f16f0f4ea1f3310cf14d2078Eugen Kuksa "email adress must belong to the fully qualified domain name '#{fqdn}'."
4e6e3beaf468728ff1435eb7935928da535ef736Eugen Kuksa class ExecutableValidator < ActiveModel::EachValidator
4e6e3beaf468728ff1435eb7935928da535ef736Eugen Kuksa def validate_each(record, attribute, value)
4e6e3beaf468728ff1435eb7935928da535ef736Eugen Kuksa unless File.executable?(value)
d7b28c193ee68ed4be93448c33c399d583de5b77Eugen Kuksa record.errors.add attribute, 'must be an executable file'