Class: Katello::Validators::AlternateContentSourcePathValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Katello::Validators::AlternateContentSourcePathValidator
- Defined in:
- app/lib/katello/validators/alternate_content_source_path_validator.rb
Class Method Summary collapse
- .validate_base_url(base_url) ⇒ Object
-
.validate_subpaths(subpaths) ⇒ Object
Subpaths must have a slash at the end and none at the front: ‘path/’.
Instance Method Summary collapse
Class Method Details
.validate_base_url(base_url) ⇒ Object
18 19 20 |
# File 'app/lib/katello/validators/alternate_content_source_path_validator.rb', line 18 def self.validate_base_url(base_url) base_url =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/ end |
.validate_subpaths(subpaths) ⇒ Object
Subpaths must have a slash at the end and none at the front: ‘path/’
23 24 25 26 |
# File 'app/lib/katello/validators/alternate_content_source_path_validator.rb', line 23 def self.validate_subpaths(subpaths) bad_subpaths = subpaths.select { |subpath| subpath[0] == '/' || subpath[-1] != '/' } bad_subpaths.empty? end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/lib/katello/validators/alternate_content_source_path_validator.rb', line 4 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 |