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

Version Path
katello-4.13.1 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.13.0 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.12.1 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.13.0.rc1 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.12.0 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.12.0.rc3 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.12.0.rc2 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.12.0.rc1 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.11.1 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.11.0 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.11.0.rc2 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.11.0.rc1 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.10.0 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.9.2 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.10.0.rc2 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.10.0.rc1 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.8.4 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.9.1 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.8.3 app/lib/katello/validators/alternate_content_source_path_validator.rb
katello-4.9.0 app/lib/katello/validators/alternate_content_source_path_validator.rb