<commit_before># frozen_string_literal: true
# :nodoc:
class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by providing a null session when the token is missing from the request.
  protect_from_forgery

  # Custom flash types. We follow Bootstrap's convention.
  add_flash_types :success, :info, :warning, :danger

  # We allow views to add breadcrumbs
  helper_method :add_breadcrumb

  include ApplicationMultitenancyConcern
  include ApplicationComponentsConcern
  include ApplicationInternationalizationConcern
  include ApplicationThemingConcern
  include ApplicationUserConcern
  include ApplicationUserTimeZoneConcern
  include ApplicationAnnouncementsConcern
  include ApplicationPaginationConcern

  rescue_from IllegalStateError, with: :handle_illegal_state_error

  protected

  # Runs the provided block with Bullet disabled.
  #
  # @note Bullet will not be enabled again after this block returns until the next Rack request.
  #   The block syntax is in anticipation of Bullet eventually supporting temporary disabling,
  #   which currently does not work. See flyerhzm/bullet#247.
  def without_bullet
    old_bullet_enable = Bullet.enable?
    Bullet.enable = false
    yield
  ensure
    Bullet.enable = old_bullet_enable
  end

  private

  # Handles +IllegalStateError+s with a HTTP 422.
  def handle_illegal_state_error(exception)
    @exception = exception
    render file: 'public/422', layout: false, status: 422
  end
end<commit_msg>Implement redirect_back with fallback ( which is avaliable in Rails 5 ) * This will help us simplify some code<commit_after># frozen_string_literal: true
# :nodoc:
class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by providing a null session when the token is missing from the request.
  protect_from_forgery

  # Custom flash types. We follow Bootstrap's convention.
  add_flash_types :success, :info, :warning, :danger

  # We allow views to add breadcrumbs
  helper_method :add_breadcrumb

  include ApplicationMultitenancyConcern
  include ApplicationComponentsConcern
  include ApplicationInternationalizationConcern
  include ApplicationThemingConcern
  include ApplicationUserConcern
  include ApplicationUserTimeZoneConcern
  include ApplicationAnnouncementsConcern
  include ApplicationPaginationConcern

  rescue_from IllegalStateError, with: :handle_illegal_state_error

  protected

  # Runs the provided block with Bullet disabled.
  #
  # @note Bullet will not be enabled again after this block returns until the next Rack request.
  #   The block syntax is in anticipation of Bullet eventually supporting temporary disabling,
  #   which currently does not work. See flyerhzm/bullet#247.
  def without_bullet
    old_bullet_enable = Bullet.enable?
    Bullet.enable = false
    yield
  ensure
    Bullet.enable = old_bullet_enable
  end

  # Redirects the browser to the page that issued the request (the referrer)
  # if possible, otherwise redirects to the provided default fallback
  # location.
  #
  # TODO: Remove this when upgrade to rails 5.
  def redirect_back(fallback_location:, **args)
    referer = request.headers['Referer']
    if referer
      redirect_to referer, **args
    else
      redirect_to fallback_location, **args
    end
  end

  private

  # Handles +IllegalStateError+s with a HTTP 422.
  def handle_illegal_state_error(exception)
    @exception = exception
    render file: 'public/422', layout: false, status: 422
  end
end
{'fraction_non_alphanumeric': 0.04653835104854927, 'fraction_numerical': 0.007469118069520253, 'mean_word_length': 4.5094936708860756, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5551220', 'n_tokens_mistral': 996, 'n_tokens_neox': 922, 'n_words': 337}