module Might::SortValueValidator
Build singleton validation class for specified attribute name @example you need a nice validator for a first_name
validator_klass = ValueValidator.build('first_name', presence: true, length: { minimum: 3 }) validator = validator_klass.new('Bo') validator.valid? #=> false validator.errors.full_messages #=> ['First name is too short (minimum is 3 characters)']
Public Class Methods
model_name()
click to toggle source
# File lib/might/sort_value_validator.rb, line 29 def self.model_name ActiveModel::Name.new(Might, nil, 'Might') end
Public Instance Methods
build(definition)
click to toggle source
# File lib/might/sort_value_validator.rb, line 20 def build(definition) Class.new do include ActiveModel::Validations validates(definition.name, 'might/sort_value_validator/defined': true) define_method(:undefined?) { definition.undefined? } define_method(definition.name) {} def self.model_name ActiveModel::Name.new(Might, nil, 'Might') end end end