Class: ConsistencyValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/tram/validators/consistency_validator.rb

Overview

Compares value of the attribute to value of another attribute

Examples:

Compares price to source.price

validates :price, consistency: { greater_than: 'source.price' }
# I18n error key 'price.greater_than_source.price'

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



8
9
10
11
12
# File 'lib/tram/validators/consistency_validator.rb', line 8

def validate_each(record, attribute, value)
  Tram::Validators::CONDITIONS.each do |key, block|
    check(key, record, attribute, value, &block)
  end
end