Class: ActiveModel::Validations::SubsetValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::SubsetValidator
- Defined in:
- lib/validates_subset.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ SubsetValidator
constructor
A new instance of SubsetValidator.
-
#validate_each(record, attribute, value) ⇒ Object
Validate that the array is a subset of what we expect.
Constructor Details
#initialize(options) ⇒ SubsetValidator
Returns a new instance of SubsetValidator.
18 19 20 21 22 23 24 25 26 |
# File 'lib/validates_subset.rb', line 18 def initialize() [:superset] = .delete(:subset) = { message: :subset }.merge() super() end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
Validate that the array is a subset of what we expect
35 36 37 |
# File 'lib/validates_subset.rb', line 35 def validate_each(record, attribute, value) add_errors_or_raise(, record, attribute) unless is_subset?(value, [:superset]) end |