Sha256: 81dac507547fd40d3da216dc315ff9a096c3bdf0341e73c5cb80860ddd827ad6
Contents?: true
Size: 1.13 KB
Versions: 56
Compression:
Stored size: 1.13 KB
Contents
module Xeroizer module Record class Validator class AssociatedValidator < Validator def valid?(record) case record.class.fields[attribute][:type] when :belongs_to return true if options[:allow_blanks] && record[attribute].nil? unless record[attribute].is_a?(Xeroizer::Record::Base) && record[attribute].valid? record.errors << [attribute, options[:message] || "must be valid"] end when :has_many return true if options[:allow_blanks] && (record[attribute].nil? || (record[attribute].is_a?(Array) && record[attribute].size == 0)) if record[attribute].is_a?(Array) && record[attribute].size > 0 unless record[attribute].all? { | r | r.is_a?(Xeroizer::Record::Base) && r.valid? } record.errors << [attribute, options[:message] || "must all be valid"] end else record.errors << [attribute, "must have one or more records"] end end end end end end end
Version data entries
56 entries across 56 versions & 2 rubygems