Class: Resto::Property::Integer

Inherits:
Object
  • Object
show all
Includes:
Resto::Property
Defined in:
lib/resto/property/integer.rb,
lib/resto/property/integer.rb

Instance Method Summary collapse

Methods included from Resto::Property

#attribute_key, #attribute_key_as_string, #remote_key, #validate, #validate_inclusion, #validate_length, #validate_presence

Constructor Details

#initialize(name, options = {}) ⇒ Integer

Returns a new instance of Integer.



13
14
15
16
# File 'lib/resto/property/integer.rb', line 13

def initialize(name, options={})
  @key = (name.to_s + "_integer").to_sym
  super
end

Instance Method Details

#cast(value, errors) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/resto/property/integer.rb', line 18

def cast(value, errors)
  errors.store(@key, nil)

  begin
    value.to_s.strip.empty? ? nil : Integer(value)
  rescue ArgumentError, TypeError
    nil.tap { errors.store(@key, ":#{attribute_key} is not an integer.") }
  end
end