687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksamodule SettingsValidationWrapper::Validators
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa class ClassValidator < ActiveModel::EachValidator
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa def validate_each(record, attribute, value)
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa unless options[:in].include?(value.class)
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa record.errors.add attribute,
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa "must have value of one of the classes: #{options[:in]}"
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa class DirectoryValidator < ActiveModel::EachValidator
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa def validate_each(record, attribute, value)
ffd58f6885596c4420ad7a7176fd5a9e28f53408Eugen Kuksa error = nil
35846855311c07295957e6bae381aa5c07392de2Eugen Kuksa begin
35846855311c07295957e6bae381aa5c07392de2Eugen Kuksa Dir.chdir(Rails.root) { value = Pathname.new(value).expand_path }
ffd58f6885596c4420ad7a7176fd5a9e28f53408Eugen Kuksa rescue ::StandardError => e
ffd58f6885596c4420ad7a7176fd5a9e28f53408Eugen Kuksa error = e
35846855311c07295957e6bae381aa5c07392de2Eugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa unless File.directory?(value)
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa record.errors.add attribute, 'is not a directory'
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
ffd58f6885596c4420ad7a7176fd5a9e28f53408Eugen Kuksa if error
ffd58f6885596c4420ad7a7176fd5a9e28f53408Eugen Kuksa record.errors.add attribute, error.message
ffd58f6885596c4420ad7a7176fd5a9e28f53408Eugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa class ElementsArePresentValidator < ActiveModel::EachValidator
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa def validate_each(record, attribute, value)
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa unless value.is_a?(Array) && value.all? { |elem| elem.present? }
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa record.errors.add attribute,
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa 'all elements must not be blank'
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa class ElementsAreUrisValidator < ActiveModel::EachValidator
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa def validate_each(record, attribute, value)
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa bad_uris = []
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa if value.is_a?(Array)
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa value.each do |elem|
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa if elem.is_a?(String)
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa begin
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa URI(elem)
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa rescue URI::InvalidURIError
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa bad_uris << elem
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa end
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa else
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa bad_uris << elem
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa end
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa end
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa end
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")}")
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa end
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa end
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa end
36dbe6db12e6e58acfe2ca3f03af7732b6c5600dEugen Kuksa
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 end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa
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 end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa unless valid
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa record.errors.add attribute,
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa "all elements must have those keys: #{options[:keys]}"
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa
87a46b6e4db760590780a339528decb20e0c2d8bEugen Kuksa class EmailHostValidator < ActiveModel::EachValidator
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa def validate_each(record, attribute, value)
8acd979bfae73bf7f16f0f4ea1f3310cf14d2078Eugen Kuksa fqdn =
8acd979bfae73bf7f16f0f4ea1f3310cf14d2078Eugen Kuksa if options[:hostname].respond_to?(:call)
8acd979bfae73bf7f16f0f4ea1f3310cf14d2078Eugen Kuksa options[:hostname].call(record)
8acd979bfae73bf7f16f0f4ea1f3310cf14d2078Eugen Kuksa else
8acd979bfae73bf7f16f0f4ea1f3310cf14d2078Eugen Kuksa options[:hostname]
8acd979bfae73bf7f16f0f4ea1f3310cf14d2078Eugen Kuksa end
87a46b6e4db760590780a339528decb20e0c2d8bEugen Kuksa if value.match(/@.*@/)
87a46b6e4db760590780a339528decb20e0c2d8bEugen Kuksa record.errors.add attribute,
87a46b6e4db760590780a339528decb20e0c2d8bEugen Kuksa 'email address must have a valid email format.'
87a46b6e4db760590780a339528decb20e0c2d8bEugen Kuksa end
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}'."
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksa end
4e6e3beaf468728ff1435eb7935928da535ef736Eugen Kuksa
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'
4e6e3beaf468728ff1435eb7935928da535ef736Eugen Kuksa end
4e6e3beaf468728ff1435eb7935928da535ef736Eugen Kuksa end
4e6e3beaf468728ff1435eb7935928da535ef736Eugen Kuksa end
687202f41b738a4e3ebecdc17946de02fdbe9febEugen Kuksaend