Class: UriComponentValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- UriComponentValidator
- Defined in:
- lib/uri_component_validator.rb
Instance Method Summary collapse
Instance Method Details
#check_validity! ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/uri_component_validator.rb', line 8 def check_validity! valid_components = URI::DEFAULT_PARSER.regexp.keys if valid_components.exclude? component raise ArgumentError, "Component must be of the following type: #{valid_components}" end end |
#component ⇒ Object
16 17 18 |
# File 'lib/uri_component_validator.rb', line 16 def component [:component] end |
#validate_each(record, attribute, value) ⇒ Object
2 3 4 5 6 |
# File 'lib/uri_component_validator.rb', line 2 def validate_each(record, attribute, value) unless value =~ URI::DEFAULT_PARSER.regexp[component] record.errors.add(attribute, :uri_component, .merge(value: value)) end end |