32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/sequent/core/helpers/param_support.rb', line 32
def from_params(params, strict_nil_check = true)
params = HashWithIndifferentAccess.new(params)
self.class.types.each do |attribute, type|
value = params[attribute]
next if strict_nil_check && value.nil?
next if (!strict_nil_check && value.blank?)
if type.respond_to? :from_params
value = type.from_params(value)
elsif value.is_a?(Array)
value = value.map do |v|
if type.item_type.respond_to?(:from_params)
type.item_type.from_params(v, strict_nil_check)
else
v
end
end
end
instance_variable_set(:"@#{attribute}", value)
end
end
|