Sha256: aaea272353c5e2676ec9c042743cbcae05040ad0a0aabeba65c53443a70e6c25

Contents?: true

Size: 803 Bytes

Versions: 33

Compression:

Stored size: 803 Bytes

Contents

class ArrayValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, values)
    [values].flatten.each do |value|
      options.each do |key, args|
        validator_options = { attributes: attribute }
        validator_options.merge!(args) if args.is_a?(Hash)

        next if value.nil? && validator_options[:allow_nil]
        next if value.blank? && validator_options[:allow_blank]

        validator_class_name = "#{key.to_s.camelize}Validator"
        validator_class = begin
          validator_class_name.constantize
        rescue NameError
          "ActiveModel::Validations::#{validator_class_name}".constantize
        end

        validator = validator_class.new(validator_options)
        validator.validate_each(record, attribute, value)
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
carte-server-1.0.11 lib/carte/server/validators/array_validator.rb
carte-server-1.0.10 lib/carte/server/validators/array_validator.rb
carte-server-1.0.9 lib/carte/server/validators/array_validator.rb
carte-server-1.0.8 lib/carte/server/validators/array_validator.rb
carte-server-1.0.7 lib/carte/server/validators/array_validator.rb
carte-server-1.0.6 lib/carte/server/validators/array_validator.rb
carte-server-1.0.5 lib/carte/server/validators/array_validator.rb
carte-server-1.0.4 lib/carte/server/validators/array_validator.rb
carte-server-1.0.3 lib/carte/server/validators/array_validator.rb
carte-server-1.0.2 lib/carte/server/validators/array_validator.rb
carte-server-1.0.1 lib/carte/server/validators/array_validator.rb
carte-server-1.0.0 lib/carte/server/validators/array_validator.rb
carte-server-0.0.28 lib/carte/server/validators/array_validator.rb
carte-server-0.0.27 lib/carte/server/validators/array_validator.rb
carte-server-0.0.26 lib/carte/server/validators/array_validator.rb
carte-server-0.0.25 lib/carte/server/validators/array_validator.rb
carte-server-0.0.24 lib/carte/server/validators/array_validator.rb
carte-server-0.0.23 lib/carte/server/validators/array_validator.rb
carte-server-0.0.22 lib/carte/server/validators/array_validator.rb
carte-server-0.0.21 lib/carte/server/validators/array_validator.rb