Class: Poncho::Params::IntegerParam

Inherits:
Poncho::Param show all
Defined in:
lib/poncho/params/integer.rb

Instance Attribute Summary

Attributes inherited from Poncho::Param

#name, #options

Instance Method Summary collapse

Methods inherited from Poncho::Param

#initialize, type, #type

Constructor Details

This class inherits a constructor from Poncho::Param

Instance Method Details

#convert(value) ⇒ Object



10
11
12
13
14
# File 'lib/poncho/params/integer.rb', line 10

def convert(value)
  Integer(value)
rescue TypeError, ArgumentError
  nil
end

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
# File 'lib/poncho/params/integer.rb', line 4

def validate_each(record, attribute, value)
  unless convert(value).is_a?(Integer)
    record.errors.add(attribute, :invalid_integer, options.merge(:value => value))
  end
end