Sha256: a094e2e67a4755c5df648872d9ff8e71ef521b33db0213870ccbb9fb04800109
Contents?: true
Size: 1.11 KB
Versions: 8
Compression:
Stored size: 1.11 KB
Contents
module ActiveModel module Validations # Builds the inner validators for the collection items validator class CollectionItemsValidator::InnerValidatorBuilder class << self def build(validator_name, options) new(validator_name, options).build end end def initialize(validator_name, options) @validator_name = validator_name @options = options end def build validator_class.new inner_options.merge(attributes: [:base]) end private attr_reader :validator_name, :options def validator_class name = "#{validator_name.to_s.camelize}Validator" begin name.include?("::") ? name.constantize : ActiveModel::Validations.const_get(name) rescue NameError raise ArgumentError, "Unknown validator: '#{validator_name}'" end end def inner_options case options when TrueClass {} when Hash options when Range, Array { in: options } else { with: options } end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems