<commit_before># frozen_string_literal: true

# rubocop:disable Metrics/BlockLength

# The priority is based upon order of creation:
# first created -> highest priority.
# See how all your routes lay out with "rake routes".

Rails.application.routes.draw do
  # Root of site
  root 'static_pages#home'

  scope '(:locale)' do
    resources :project_stats

    get 'sessions/new'

    get 'signup' => 'users#new'
    get 'home' => 'static_pages#home'
    get 'background' => 'static_pages#background'
    get 'criteria' => 'static_pages#criteria'

    get 'feed' => 'projects#feed', defaults: { format: 'atom' }
    get 'reminders' => 'projects#reminders_summary'

    resources :projects do
      member do
        get 'badge', defaults: { format: 'svg' }
        get '' => 'projects#show_json',
            constraints: ->(req) { req.format == :json }
        get ':level(.:format)' => 'projects#show',
            constraints: { level: /[0-2]/ }
        get ':level/edit(.:format)' => 'projects#edit',
            constraints: { level: /[0-2]/ }
      end
    end
    match(
      'projects/:id/(:level/)edit' => 'projects#update',
      via: %i[put patch], as: :put_project,
      constraints: { level: /[0-2]/ }
    )

    resources :users
    resources :account_activations, only: [:edit]
    resources :password_resets,     only: %i[new create edit update]

    get 'login' => 'sessions#new'
    post 'login' => 'sessions#create'
    delete 'logout' => 'sessions#destroy'

    get 'auth/:provider/callback' => 'sessions#create'
    get '/signout' => 'sessions#destroy', as: :signout
  end

  # If no route found in some cases, just redirect to a 404 page.
  # The production site is constantly hit by nonsense paths,
  # and while Rails has a built-in mechanism to handle nonsense,
  # Rails' built-in mechanism creates noisy logs.
  # Ideally we'd redirect all no-match cases quickly to a 404 handler.
  # Unfortunately, the noise-reduction approach for Rails 4 noted here:
  # http://rubyjunky.com/cleaning-up-rails-4-production-logging.html
  # works in development but does NOT work in production.
  # So instead, we'll select a few common cases where we have nothing
  # and there's no possible security problem, and fast-path its rejection
  # by redirecting to a 404 (without a lengthy log of the cause).
  # wp-login.php queries are evidences of WordPress brute-force attacks:<commit_msg>DRY config/routes.rb - define level syntax exactly once<commit_after># frozen_string_literal: true

# rubocop:disable Metrics/BlockLength

# The priority is based upon order of creation:
# first created -> highest priority.
# See how all your routes lay out with "rake routes".

Rails.application.routes.draw do
  # Root of site
  root 'static_pages#home'

  scope '(:locale)' do
    resources :project_stats

    get 'sessions/new'

    get 'signup' => 'users#new'
    get 'home' => 'static_pages#home'
    get 'background' => 'static_pages#background'
    get 'criteria' => 'static_pages#criteria'

    get 'feed' => 'projects#feed', defaults: { format: 'atom' }
    get 'reminders' => 'projects#reminders_summary'

    VALID_LEVEL = /[0-2]/
    resources :projects do
      member do
        get 'badge', defaults: { format: 'svg' }
        get '' => 'projects#show_json',
            constraints: ->(req) { req.format == :json }
        get ':level(.:format)' => 'projects#show',
            constraints: { level: VALID_LEVEL }
        get ':level/edit(.:format)' => 'projects#edit',
            constraints: { level: VALID_LEVEL }
      end
    end
    match(
      'projects/:id/(:level/)edit' => 'projects#update',
      via: %i[put patch], as: :put_project,
      constraints: { level: VALID_LEVEL }
    )

    resources :users
    resources :account_activations, only: [:edit]
    resources :password_resets,     only: %i[new create edit update]

    get 'login' => 'sessions#new'
    post 'login' => 'sessions#create'
    delete 'logout' => 'sessions#destroy'

    get 'auth/:provider/callback' => 'sessions#create'
    get '/signout' => 'sessions#destroy', as: :signout
  end

  # If no route found in some cases, just redirect to a 404 page.
  # The production site is constantly hit by nonsense paths,
  # and while Rails has a built-in mechanism to handle nonsense,
  # Rails' built-in mechanism creates noisy logs.
  # Ideally we'd redirect all no-match cases quickly to a 404 handler.
  # Unfortunately, the noise-reduction approach for Rails 4 noted here:
  # http://rubyjunky.com/cleaning-up-rails-4-production-logging.html
  # works in development but does NOT work in production.
  # So instead, we'll select a few common cases where we have nothing
  # and there's no possible security problem, and fast-path its rejection
  # by redirecting to a 404 (without a lengthy log of the cause).
  # wp-login.php queries are evidences of WordPress brute-force attacks:
{'fraction_non_alphanumeric': 0.11998361998361998, 'fraction_numerical': 0.006142506142506142, 'mean_word_length': 3.255226480836237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '4070519', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1451, 'n_words': 495}