Sha256: 711e78346dd30a19d8fee92ed010b60705f79114a2ea2a07c9db71d184f370f2
Contents?: true
Size: 1.03 KB
Versions: 46
Compression:
Stored size: 1.03 KB
Contents
module Katello module Validators class AlternateContentSourcePathValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) if value if attribute == :base_url unless AlternateContentSourcePathValidator.validate_base_url(value) record.errors[attribute] << N_("%s is not a valid path") % value end elsif attribute == :subpaths unless AlternateContentSourcePathValidator.validate_subpaths(value) record.errors[attribute] << N_('All subpaths must have a slash at the end and none at the front') end end end end def self.validate_base_url(base_url) base_url =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/ end # Subpaths must have a slash at the end and none at the front: 'path/' def self.validate_subpaths(subpaths) bad_subpaths = subpaths.select { |subpath| subpath[0] == '/' || subpath[-1] != '/' } bad_subpaths.empty? end end end end
Version data entries
46 entries across 46 versions & 1 rubygems