projects/model/src/model.rb in foobara-0.0.22 vs projects/model/src/model.rb in foobara-0.0.23
- old
+ new
@@ -205,12 +205,18 @@
attributes.each_pair do |attribute_name, value|
write_attribute(attribute_name, value)
end
end
- # why do we default to true here but false in the transformers?
- mutable = options.key?(:mutable) ? options[:mutable] : true
+ mutable = if options.key?(:mutable)
+ options[:mutable]
+ elsif self.class.model_type.declaration_data.key?(:mutable)
+ self.class.model_type.declaration_data[:mutable]
+ else
+ # why do we default to true here but false in the transformers?
+ true
+ end
self.mutable = if mutable.is_a?(::Array)
mutable.map(&:to_sym)
else
mutable
@@ -226,10 +232,10 @@
end
def write_attribute(attribute_name, value)
attribute_name = attribute_name.to_sym
- if mutable == true || mutable&.include?(attribute_name)
+ if mutable == true || (mutable != false && mutable&.include?(attribute_name))
outcome = cast_attribute(attribute_name, value)
attributes[attribute_name] = outcome.success? ? outcome.result : value
else
# :nocov:
raise AttributeIsImmutableError, "Cannot write attribute #{attribute_name} because it is not mutable"