<commit_before>require 'logger'

namespace :router do
  task :router_environment => :environment do
    require 'plek'
    require 'gds_api/router'
    @logger = Logger.new STDOUT
    @logger.level = Logger::DEBUG
    @router_api = GdsApi::Router.new(Plek.current.find('router-api'))
    @application_id = "whitehall-frontend"
  end

  task :register_backend => :router_environment do
    @logger.info "Registering application..."
    @router_api.add_backend(@application_id, Plek.current.find('whitehall-frontend', :force_http => true) + "/")
  end

  task :register_routes => :router_environment do
    @router_api.add_route("/government", "prefix", @application_id)
  end

  task :register_guidance => [:router_environment, :register_backend] do
    DetailedGuide.published.includes(:document).each do |guide|
      path = "/#{guide.slug}"
      @logger.info "Registering detailed guide #{path}..."
      @router_api.add_route(path, "exact", @application_id, skip_commit: true)
    end
    @logger.info "Guides registered, reloading routes..."
    @router_api.commit_routes
  end

  desc "Register whitehall application and routes with the router (run this task on server in cluster)"
  task :register => [ :register_backend, :register_routes ]
end<commit_msg>Don't load Rails for most tasks; improve docs<commit_after>require 'logger'

namespace :router do
  task :router_environment do
    require 'plek'
    require 'gds_api/router'
    @logger = Logger.new STDOUT
    @logger.level = Logger::DEBUG
    @router_api = GdsApi::Router.new(Plek.current.find('router-api'))
    @application_id = "whitehall-frontend"
  end

  desc "Register the whitehall backend with the router"
  task :register_backend => :router_environment do
    @logger.info "Registering application..."
    @router_api.add_backend(@application_id, Plek.current.find('whitehall-frontend', :force_http => true) + "/")
  end

  desc "Register the government prefix with the router"
  task :register_routes => :router_environment do
    @router_api.add_route("/government", "prefix", @application_id)
  end

  desc "Register all detailed guides with the router"
  task :register_guidance => [:environment, :router_environment, :register_backend] do
    DetailedGuide.published.includes(:document).each do |guide|
      path = "/#{guide.slug}"
      @logger.info "Registering detailed guide #{path}..."
      @router_api.add_route(path, "exact", @application_id, skip_commit: true)
    end
    @logger.info "Guides registered, reloading routes..."
    @router_api.commit_routes
  end

  desc "Register whitehall backend and routes with the router"
  task :register => [ :register_backend, :register_routes ]
end
{'fraction_non_alphanumeric': 0.11898545318910854, 'fraction_numerical': 0.0, 'mean_word_length': 4.364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '2319436', 'n_tokens_mistral': 812, 'n_tokens_neox': 800, 'n_words': 207}