Class: Hipaa::Enum::Validators::MultipleValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Hipaa::Enum::Validators::MultipleValidator
- Defined in:
- lib/hipaa/enum/validators/multiple_validator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_error_message(record, attribute) ⇒ Object
- #all_included?(values, allowed) ⇒ Boolean
- #validate_each(record, attribute, values) ⇒ Object
Class Method Details
.kind ⇒ Object
23 24 25 |
# File 'lib/hipaa/enum/validators/multiple_validator.rb', line 23 def self.kind :custom end |
Instance Method Details
#add_error_message(record, attribute) ⇒ Object
15 16 17 |
# File 'lib/hipaa/enum/validators/multiple_validator.rb', line 15 def (record, attribute) record.errors[attribute] << ([:message] || "is not in #{[:in].join ", "}") end |
#all_included?(values, allowed) ⇒ Boolean
19 20 21 |
# File 'lib/hipaa/enum/validators/multiple_validator.rb', line 19 def all_included?(values, allowed) (values - allowed).empty? end |
#validate_each(record, attribute, values) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/hipaa/enum/validators/multiple_validator.rb', line 5 def validate_each(record, attribute, values) values = Array(values) if [:allow_nil] record, attribute if !all_included?(values, [:in]) else record, attribute if values.empty? || !all_included?(values, [:in]) end end |