Class: PartitionalValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- PartitionalValidator
- Defined in:
- lib/partitional/validator.rb
Constant Summary collapse
- ALLOWED_OPTIONS =
%i[ allow_nil allow_blank if unless message attributes ]
Instance Method Summary collapse
Instance Method Details
#check_validity! ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/partitional/validator.rb', line 13 def check_validity! invalid_keys = [] .except(*ALLOWED_OPTIONS).each_pair do |key, value| invalid_keys.push("#{key}: #{value}") end raise ArgumentError, "#{invalid_keys.join(', ')} is invalid options." unless invalid_keys.empty? end |
#validate_each(record, attribute, value) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/partitional/validator.rb', line 21 def validate_each(record, attribute, value) return if [:if].present? && !to_value(record, [:if]) return if [:unless].present? && to_value(record, [:unless]) value.validate mapping = value.mapping value.errors.each do |error| record.errors.add(mapping[error.attribute], error.) end end |