<commit_before>require "bugsnag"
require "rack/csrf"
require "dry/web/application"
require_relative "container"
require "roda_plugins"

module Main
  class Application < Dry::Web::Application
    configure do |config|
      config.routes = "web/routes".freeze
      config.container = Container
    end

    opts[:root] = Pathname(__FILE__).join("../..").realpath.dirname

    use Rack::Session::Cookie, key: "app_prototype.session", secret: AppPrototype::Container["config"].session_secret
    use Rack::Csrf, raise: true
    use Bugsnag::Rack

    plugin :error_handler
    plugin :flash

    plugin :view
    plugin :page

    def name
      :main
    end

    route do |r|
      r.root do
        r.view "home"
      end

      r.multi_route
    end

    error do |e|
      Bugsnag.auto_notify e

      if ENV["RACK_ENV"] == "production"
        if e.is_a?(ROM::TupleCountMismatchError)
          response.status = 404
          self.class["main.views.errors.error_404"].(scope: current_page)
        else
          self.class["main.views.errors.error_500"].(scope: current_page)
        end
      else<commit_msg>Only notify for worthy errors in production<commit_after>require "bugsnag"
require "rack/csrf"
require "dry/web/application"
require_relative "container"
require "roda_plugins"

module Main
  class Application < Dry::Web::Application
    configure do |config|
      config.routes = "web/routes".freeze
      config.container = Container
    end

    opts[:root] = Pathname(__FILE__).join("../..").realpath.dirname

    use Rack::Session::Cookie, key: "app_prototype.session", secret: AppPrototype::Container["config"].session_secret
    use Rack::Csrf, raise: true
    use Bugsnag::Rack

    plugin :error_handler
    plugin :flash

    plugin :view
    plugin :page

    def name
      :main
    end

    route do |r|
      r.root do
        r.view "home"
      end

      r.multi_route
    end

    error do |e|
      if ENV["RACK_ENV"] == "production"
        if e.is_a?(ROM::TupleCountMismatchError)
          response.status = 404
          self.class["main.views.errors.error_404"].(scope: current_page)
        else
          Bugsnag.auto_notify e
          self.class["main.views.errors.error_500"].(scope: current_page)
        end
      else
        Bugsnag.auto_notify e
{'fraction_non_alphanumeric': 0.11178773379730318, 'fraction_numerical': 0.0078294910830796, 'mean_word_length': 2.6565977742448332, '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': '7130132', 'n_tokens_mistral': 740, 'n_tokens_neox': 710, 'n_words': 163}