Class: DataMapper::Validations::NumericalityValidator

Inherits:
GenericValidator show all
Defined in:
lib/dm-validations/validators/numeric_validator.rb

Overview

Author:

  • Guy van den Berg

Since:

  • 0.9

Instance Attribute Summary

Attributes inherited from GenericValidator

#field_name, #humanized_field_name, #if_clause, #options, #unless_clause

Instance Method Summary collapse

Methods inherited from GenericValidator

#==, #add_error, #evaluate_conditional_clause, #execute?, #initialize, #inspect, #optional?, #set_optional_by_default

Constructor Details

This class inherits a constructor from DataMapper::Validations::GenericValidator

Instance Method Details

#call(target) ⇒ Object

Since:

  • 0.9



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dm-validations/validators/numeric_validator.rb', line 7

def call(target)
  value = target.validation_property_value(field_name)
  return true if optional?(value)

  errors = []

  validate_with(integer_only? ? :integer : :numeric, value, errors)

  add_errors(target, errors)

  # if the number is invalid, skip further tests
  return false if errors.any?

  [ :gt, :lt, :gte, :lte, :eq, :ne ].each do |validation_type|
    validate_with(validation_type, value, errors)
  end

  add_errors(target, errors)

  errors.empty?
end