Sha256: 9182febcbcc84c183b21c181f41c10fa34d0dbe37623beb0c4f5d8cfb0290128

Contents?: true

Size: 1.9 KB

Versions: 15

Compression:

Stored size: 1.9 KB

Contents

# frozen-string-literal: true

module Sequel
  # Exception class raised when +raise_on_save_failure+ is set and an action is canceled in a hook.
  # or an around hook doesn't yield.
  class HookFailed < Error
    # The Sequel::Model instance related to this error.
    attr_reader :model

    def initialize(message=nil, model=nil)
      @model = model
      super(message)
    end
  end

  (
  # Exception class raised when +require_modification+ is set and an UPDATE or DELETE statement to modify the dataset doesn't
  # modify a single row.
  NoExistingObject = Class.new(Error)
  ).name
  
  (
  # 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.
  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

    # The Sequel::Model::Errors object related to this exception.
    attr_reader :errors

    def initialize(errors=nil)
      if errors.is_a?(Sequel::Model)
        @model = errors
        errors = @model.errors
      end

      if errors.respond_to?(:full_messages)
        @errors = errors
        super(errors.full_messages.join(', '))
      else
        super
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
sequel-5.86.0 lib/sequel/model/exceptions.rb
sequel-5.85.0 lib/sequel/model/exceptions.rb
sequel-5.84.0 lib/sequel/model/exceptions.rb
sequel-5.83.1 lib/sequel/model/exceptions.rb
sequel-5.83.0 lib/sequel/model/exceptions.rb
sequel-5.82.0 lib/sequel/model/exceptions.rb
sequel-5.81.0 lib/sequel/model/exceptions.rb
sequel-5.80.0 lib/sequel/model/exceptions.rb
sequel-5.79.0 lib/sequel/model/exceptions.rb
sequel-5.78.0 lib/sequel/model/exceptions.rb
sequel-5.77.0 lib/sequel/model/exceptions.rb
sequel-5.76.0 lib/sequel/model/exceptions.rb
sequel-5.75.0 lib/sequel/model/exceptions.rb
sequel-5.74.0 lib/sequel/model/exceptions.rb
sequel-5.73.0 lib/sequel/model/exceptions.rb