module SmoothOperator::TypeCasting
Constants
- FALSE_VALUES
- TRUE_VALUES
RIPPED FROM RAILS
Public Instance Methods
cast_to_type(name, value, parent_object)
click to toggle source
# File lib/smooth_operator/type_casting.rb, line 10 def cast_to_type(name, value, parent_object) type, known_attribute, unknown_hash_class = extract_args(parent_object.class, name) return Helpers.duplicate(value) if known_attribute && type.nil? case value when Array value.map { |array_entry| cast_to_type(name, array_entry, parent_object) } when Hash type.nil? ? new_unknown_hash(value, unknown_hash_class, parent_object) : type.new(value, parent_object: parent_object) else convert(value, type) end end