74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/default_value_for/core.rb', line 74
def initialize_with_defaults(attrs = nil)
initialize_without_defaults(attrs) do
if attrs
stringified_attrs = attrs.stringify_keys
safe_attrs = if respond_to? :sanitize_for_mass_assignment
sanitize_for_mass_assignment(stringified_attrs)
else
remove_attributes_protected_from_mass_assignment(stringified_attrs)
end
safe_attribute_names = safe_attrs.keys.map do |x|
x.to_s
end
end
self.class._default_attribute_values.each do |attribute, container|
if safe_attribute_names.nil? || !safe_attribute_names.any? { |attr_name| attr_name =~ /^#{attribute}($|\()/ }
__send__("#{attribute}=", container.evaluate(self))
changed_attributes.delete(attribute)
end
end
yield(self) if block_given?
end
end
|