class Scim::Kit::V2::ComplexAttributeValidator

Validates a complex attribute

Public Instance Methods

validate(item) click to toggle source
# File lib/scim/kit/v2/complex_attribute_validator.rb, line 8
def validate(item)
  if item._type.multi_valued
    multi_valued_validation(item)
  else
    item.each do |attribute|
      item.errors.merge!(attribute.errors) unless attribute.valid?
    end
  end
end

Private Instance Methods

multi_valued_validation(item) click to toggle source
# File lib/scim/kit/v2/complex_attribute_validator.rb, line 20
def multi_valued_validation(item)
  item.each_value do |hash|
    validated = hash.map do |key, value|
      attribute = item.attribute_for(key)
      attribute._assign(value)
      item.errors.merge!(attribute.errors) unless attribute.valid?

      key.to_sym
    end
    validate_missing(item, hash, validated)
  end
end
validate_missing(item, hash, validated) click to toggle source
# File lib/scim/kit/v2/complex_attribute_validator.rb, line 33
def validate_missing(item, hash, validated)
  not_validated = item.map { |x| x._type.name.to_sym } - validated
  not_validated.each do |key|
    attribute = item.attribute_for(key)
    attribute._assign(hash[key])
    item.errors.merge!(attribute.errors) unless attribute.valid?
  end
end