70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/vex/active_record/plugins/default_value_for/init.rb', line 70
def initialize_with_defaults(attrs = nil)
initialize_without_defaults(attrs) do
if attrs
stringified_attrs = attrs.stringify_keys
safe_attrs = remove_attributes_protected_from_mass_assignment(stringified_attrs)
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.none? { |attr_name| attr_name =~ /^#{attribute}($|\()/ }
__send__("#{attribute}=", container.evaluate(self))
changed_attributes.delete(attribute)
end
end
yield(self) if block_given?
end
end
|