Class: Hashme::Validations::CastedAttributeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/hashme/validations/casted_attribute_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(document, attribute, value) ⇒ Object



5
6
7
8
9
10
# File 'lib/hashme/validations/casted_attribute_validator.rb', line 5

def validate_each(document, attribute, value)
  is_array = value.is_a?(Array) || value.is_a?(CastedArray)
  values = is_array ? value : [value]
  return if values.collect {|attr| attr.nil? || attr.valid? }.all?
  document.errors.add(attribute)
end