Class: Resto::Property::Integer
- Inherits:
-
Object
- Object
- Resto::Property::Integer
- Includes:
- Resto::Property
- Defined in:
- lib/resto/property/integer.rb,
lib/resto/property/integer.rb
Instance Method Summary collapse
- #cast(value, errors) ⇒ Object
-
#initialize(name, options = {}) ⇒ Integer
constructor
A new instance of Integer.
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, ={}) @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 |