lib/sequel/model/exceptions.rb in sequel-5.72.0 vs lib/sequel/model/exceptions.rb in sequel-5.73.0
- old
+ new
@@ -22,14 +22,26 @@
(
# Raised when an undefined association is used when eager loading.
UndefinedAssociation = Class.new(Error)
).name
- (
# Raised when a mass assignment method is called in strict mode with either a restricted column
# or a column without a setter method.
- MassAssignmentRestriction = Class.new(Error)
- ).name
+ class MassAssignmentRestriction < Error
+ # The Sequel::Model object related to this exception.
+ attr_reader :model
+
+ # The column related to this exception, as a string.
+ attr_reader :column
+
+ # Create an instance of this class with the model and column set.
+ def self.create(msg, model, column)
+ e = new("#{msg} for class #{model.class.inspect}")
+ e.instance_variable_set(:@model, model)
+ e.instance_variable_set(:@column, column)
+ e
+ end
+ end
# Exception class raised when +raise_on_save_failure+ is set and validation fails
class ValidationFailed < Error
# The Sequel::Model object related to this exception.
attr_reader :model