Sha256: 5b99384f46fa7cfd001d5010e785c2436c7db52e9e8d0ed13b7458c9caf2f8b4

Contents?: true

Size: 388 Bytes

Versions: 12

Compression:

Stored size: 388 Bytes

Contents

module HashieModel
  class AssociatedValidator < ActiveModel::EachValidator
    def validate_each(record, attribute, value)
      return if (value.is_a?(Array) ? value : [value]).collect{ |r| r.nil? || r.valid? }.all?
      errors = value.is_a?(Array) ? value.map(&:errors).first : value.errors
      record.errors.add(attribute, errors, options.merge(:value => value))
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hashie-model-1.3.8 lib/hashie_model/associated_validator.rb
hashie-model-1.3.7 lib/hashie_model/associated_validator.rb
hashie-model-1.3.6 lib/hashie_model/associated_validator.rb
hashie-model-1.3.5 lib/hashie_model/associated_validator.rb
hashie-model-1.3.4 lib/hashie_model/associated_validator.rb
hashie-model-1.3.3 lib/hashie_model/associated_validator.rb
hashie-model-1.3.2 lib/hashie_model/associated_validator.rb
hashie-model-1.3.1 lib/hashie_model/associated_validator.rb
hashie-model-1.3.0 lib/hashie_model/associated_validator.rb
hashie-model-1.2.3 lib/hashie_model/associated_validator.rb
hashie-model-1.2.1 lib/hashie_model/associated_validator.rb
hashie-model-1.2.0 lib/hashie_model/associated_validator.rb