Sha256: fc965627914019786e2fd1c4cfff6a95d0569f9ab9d27c80432b1d49fc9da689

Contents?: true

Size: 1.69 KB

Versions: 32

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true
module ActiveAdmin
  # Exception class to raise when there is an authorized access
  # exception thrown. The exception has a few goodies that may
  # be useful for capturing / recognizing security issues.
  class AccessDenied < StandardError
    attr_reader :user, :action, :subject

    def initialize(user, action, subject = nil)
      @user = user
      @action = action
      @subject = subject

      super()
    end

    def message
      I18n.t("active_admin.access_denied.message")
    end
  end

  class Error < RuntimeError
  end

  class ErrorLoading < Error
    # Locates the most recent file and line from the caught exception's backtrace.
    def find_cause(folder, backtrace)
      backtrace.grep(/\/(#{folder}\/.*\.rb):(\d+)/) { [$1, $2] }.first
    end
  end

  class DatabaseHitDuringLoad < ErrorLoading
    def initialize(exception)
      file, line = find_cause(:app, exception.backtrace)

      super "Your file, #{file} (line #{line}), caused a database error while Active Admin was loading. This " +
            "is most common when your database is missing or doesn't have the latest migrations applied. To " +
            "prevent this error, move the code to a place where it will only be run when a page is rendered. " +
            "One solution can be, to wrap the query in a Proc. " +
            "Original error message: #{exception.message}"
    end

    def self.capture
      yield
    rescue *database_error_classes => exception
      raise new exception
    end

    def self.database_error_classes
      @classes ||= []
    end
  end

  class DependencyError < ErrorLoading
  end

  class NoMenuError < KeyError
  end

  class GeneratorError < Error
  end

end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
activeadmin-4.0.0.beta15 lib/active_admin/error.rb
activeadmin-4.0.0.beta14 lib/active_admin/error.rb
activeadmin-4.0.0.beta13 lib/active_admin/error.rb
activeadmin-4.0.0.beta12 lib/active_admin/error.rb
activeadmin-3.2.5 lib/active_admin/error.rb
activeadmin-4.0.0.beta11 lib/active_admin/error.rb
activeadmin-3.2.4 lib/active_admin/error.rb
activeadmin-4.0.0.beta10 lib/active_admin/error.rb
activeadmin-4.0.0.beta9 lib/active_admin/error.rb
activeadmin-3.2.3 lib/active_admin/error.rb
activeadmin-4.0.0.beta8 lib/active_admin/error.rb
activeadmin-4.0.0.beta7 lib/active_admin/error.rb
activeadmin-3.2.2 lib/active_admin/error.rb
activeadmin-4.0.0.beta6 lib/active_admin/error.rb
activeadmin-3.2.1 lib/active_admin/error.rb
activeadmin-4.0.0.beta5 lib/active_admin/error.rb
activeadmin-4.0.0.beta4 lib/active_admin/error.rb
activeadmin-4.0.0.beta3 lib/active_admin/error.rb
activeadmin-4.0.0.beta2 lib/active_admin/error.rb
activeadmin-4.0.0.beta1 lib/active_admin/error.rb