class ActiveModel::Validations::CollectionItemsValidator::InnerValidatorBuilder

Builds the inner validators for the collection items validator

Attributes

options[R]
validator_name[R]

Public Class Methods

build(validator_name, options) click to toggle source
# File lib/active_model/validations/collection_items_validator/inner_validator_builder.rb, line 6
def build(validator_name, options)
  new(validator_name, options).build
end
new(validator_name, options) click to toggle source
# File lib/active_model/validations/collection_items_validator/inner_validator_builder.rb, line 11
def initialize(validator_name, options)
  @validator_name = validator_name
  @options = options
end

Public Instance Methods

build() click to toggle source
# File lib/active_model/validations/collection_items_validator/inner_validator_builder.rb, line 16
def build
  validator_class.new inner_options.merge(attributes: [:base])
end

Private Instance Methods

inner_options() click to toggle source
# File lib/active_model/validations/collection_items_validator/inner_validator_builder.rb, line 34
def inner_options
  case options
  when TrueClass
    {}
  when Hash
    options
  when Range, Array
    { in: options }
  else
    { with: options }
  end
end
validator_class() click to toggle source
# File lib/active_model/validations/collection_items_validator/inner_validator_builder.rb, line 24
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