Module: ActiveModel::Validations::Comparability

Included in:
ComparisonValidator, NumericalityValidator
Defined in:
lib/active_model/validations/comparability.rb

Overview

:nodoc:

Constant Summary collapse

COMPARE_CHECKS =
{ greater_than: :>, greater_than_or_equal_to: :>=,
equal_to: :==, less_than: :<, less_than_or_equal_to: :<=,
other_than: :!= }.freeze

Instance Method Summary collapse

Instance Method Details

#error_options(value, option_value) ⇒ Object



21
22
23
24
25
26
# File 'lib/active_model/validations/comparability.rb', line 21

def error_options(value, option_value)
  options.except(*COMPARE_CHECKS.keys).merge!(
    count: option_value,
    value: value
  )
end

#option_value(record, option_value) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/active_model/validations/comparability.rb', line 10

def option_value(record, option_value)
  case option_value
  when Proc
    option_value.call(record)
  when Symbol
    record.send(option_value)
  else
    option_value
  end
end