Method: ActiveModel::Validations::ArrayValidator#initialize
- Defined in:
- lib/can_has_validations/validators/array_validator.rb
#initialize(options) ⇒ ArrayValidator
Returns a new instance of ArrayValidator.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/can_has_validations/validators/array_validator.rb', line 40 def initialize() record_class = [:class] super record_class.extend DefaultKeys defaults = .dup validations = defaults.slice!(*record_class.send(:_validates_default_keys), :attributes) raise ArgumentError, "You need to supply at least one validation for :#{kind}" if validations.empty? defaults[:attributes] = attributes @validators = validations.map do |key, | next unless if (cond_keys = ().keys & i(if on unless)).any? raise ArgumentError, ":#{kind} does not support conditionals on sub-validators - found on #{key}: #{cond_keys.map(&:inspect).join(', ')}" end key = "#{key.to_s.camelize}Validator" begin klass = key.include?("::".freeze) ? key.constantize : record_class.const_get(key) rescue NameError raise ArgumentError, "Unknown validator: '#{key}'" end klass.new(defaults.merge(()).except(:if, :on, :unless)) end end |