Sha256: c6bb71cde61230b4d5cc5a8c8433777071204287a947b34115279d327adfc54c
Contents?: true
Size: 502 Bytes
Versions: 1
Compression:
Stored size: 502 Bytes
Contents
require "min_max_validator/version" require 'active_model' class MinMaxValidator < ActiveModel::Validator def validate(record) min = record.send options[:fields][:min] max = record.send options[:fields][:max] unless valid_max_value?(min: min, max: max) record.errors.add(options[:fields][:max], options[:fields][:msg]) end end private def valid_max_value?(min: 0, max: nil) if min.present? && max.present? max >= min else true end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
min_max_validator-0.0.3 | lib/min_max_validator.rb |