Class: UuidValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- UuidValidator
- Defined in:
- lib/solid/validators/uuid_validator.rb
Constant Summary collapse
- CASE_SENSITIVE =
/\A#{PATTERN}\z/.freeze
- CASE_INSENSITIVE =
/\A#{PATTERN}\z/i.freeze
Instance Method Summary collapse
Instance Method Details
#validate_each(model, attribute, value) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/solid/validators/uuid_validator.rb', line 8 def validate_each(model, attribute, value) case_sensitive = .fetch(:case_sensitive, true) return model.errors.add(attribute, :blank, **) if value.blank? regexp = case_sensitive ? CASE_SENSITIVE : CASE_INSENSITIVE return if value.is_a?(String) && value.match?(regexp) model.errors.add(attribute, :invalid, **) end |