Class: Katello::Validators::KatelloLabelFormatValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Katello::Validators::KatelloLabelFormatValidator
- Defined in:
- app/lib/katello/validators/katello_label_format_validator.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.validate_length(record, attribute, value, max_length = 128, min_length = 1) ⇒ Object
14 15 16 17 18 19 |
# File 'app/lib/katello/validators/katello_label_format_validator.rb', line 14 def self.validate_length(record, attribute, value, max_length = 128, min_length = 1) if value record.errors[attribute] << N_("cannot contain more than %s characters") % max_length unless value.length <= max_length record.errors[attribute] << N_("must contain at least %s character") % min_length unless value.length >= min_length end end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'app/lib/katello/validators/katello_label_format_validator.rb', line 4 def validate_each(record, attribute, value) if value record.errors[attribute] << N_("cannot contain characters other than ascii alpha numerals, '_', '-'. ") unless value =~ /\A[a-zA-Z0-9_\-]+\z/ NoTrailingSpaceValidator.validate_trailing_space(record, attribute, value) KatelloLabelFormatValidator.validate_length(record, attribute, value) else record.errors[attribute] << N_("can't be blank") end end |