Method: ActiveEntity::Typecasting#cast!

Defined in:
lib/active_entity/typecasting.rb

#cast!nil

Try to cast attribute values. When fails to cast, raises the error and rollbacks all values.

Returns:

  • (nil)

Raises:



8
9
10
11
12
13
14
15
16
17
# File 'lib/active_entity/typecasting.rb', line 8

def cast!
  casted_values = defined_attributes.map do |name, attr|
    value = public_send(name)
    next [name, nil] if value.nil?
    [name, attr.cast!(value)]
  end

  casted_values.each {|name, casted| public_send("#{name}=", casted) }
  nil
end