<commit_before>require 'gaffe/version'

require 'ostruct'
require 'pathname'
require 'gaffe/errors'

module Gaffe
  # Yield a block to populate @configuration
  def self.configure
    yield configuration
  end

  # Return the configuration settings
  def self.configuration
    @configuration ||= OpenStruct.new
  end

  # Return our default controller
  def self.builtin_errors_controller
    @builtin_errors_controller ||= begin
      require 'gaffe/errors_controller'
      Gaffe::ErrorsController
    end
  end

  # Configure Rails to use our code when encountering exceptions
  def self.enable!
    Rails.application.config.exceptions_app = lambda do |env|
      Gaffe.errors_controller_for_request(env).action(:show).call(env)
    end
  end

  # Return the right errors controller to use for the request that
  # triggered the error
  def self.errors_controller_for_request(env)
    controller = configuration.errors_controller

    if controller.is_a?(Hash)

      # detect in namespace or subdomain

      if controller.has_key?(:subdomain)
          controller = controller[:subdomain].find { |pattern, _| (env['SERVER_NAME'] =~ pattern) == 0}.try(:last)
      elsif controller.has_key?(:namespace)
          controller = controller[:namespace].find { |pattern, _| (env['REQUEST_URI'] =~ pattern or env['REQUEST_PATH' =~ pattern]) == 0 }.try(:last)
      else
          controller = controller.find { |pattern, _| env['REQUEST_URI'] =~ pattern }.try(:last)
      end

    end

    controller ||= builtin_errors_controller

    controller.respond_to?(:constantize) ? controller.constantize : controller
  end

  # Return the root path of the gem
  def self.root
    Pathname.new(File.expand_path('../../', __FILE__))
  end
end<commit_msg>[FIX] wrong bracket<commit_after>require 'gaffe/version'

require 'ostruct'
require 'pathname'
require 'gaffe/errors'

module Gaffe
  # Yield a block to populate @configuration
  def self.configure
    yield configuration
  end

  # Return the configuration settings
  def self.configuration
    @configuration ||= OpenStruct.new
  end

  # Return our default controller
  def self.builtin_errors_controller
    @builtin_errors_controller ||= begin
      require 'gaffe/errors_controller'
      Gaffe::ErrorsController
    end
  end

  # Configure Rails to use our code when encountering exceptions
  def self.enable!
    Rails.application.config.exceptions_app = lambda do |env|
      Gaffe.errors_controller_for_request(env).action(:show).call(env)
    end
  end

  # Return the right errors controller to use for the request that
  # triggered the error
  def self.errors_controller_for_request(env)
    controller = configuration.errors_controller

    if controller.is_a?(Hash)

      # detect in namespace or subdomain

      if controller.has_key?(:subdomain)
          controller = controller[:subdomain].find { |pattern, _| (env['SERVER_NAME'] =~ pattern) == 0}.try(:last)
      elsif controller.has_key?(:namespace)
          controller = controller[:namespace].find { |pattern, _| (env['REQUEST_URI'] =~ pattern or env['REQUEST_PATH'] =~ pattern) == 0 }.try(:last)
      else
          controller = controller.find { |pattern, _| env['REQUEST_URI'] =~ pattern }.try(:last)
      end

    end

    controller ||= builtin_errors_controller

    controller.respond_to?(:constantize) ? controller.constantize : controller
  end

  # Return the root path of the gem
  def self.root
    Pathname.new(File.expand_path('../../', __FILE__))
  end
end
{'fraction_non_alphanumeric': 0.10005717552887364, 'fraction_numerical': 0.0011435105774728416, 'mean_word_length': 3.6344370860927153, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6905661', 'n_tokens_mistral': 1016, 'n_tokens_neox': 989, 'n_words': 269}