<commit_before>module Compendium
  class ReportsController < ::ApplicationController
    helper Compendium::ReportsHelper

    before_filter :find_report
    before_filter :run_report, only: :run

    def setup
      render locals: { report: @report_class.new(params[:report] || {}), prefix: @prefix }
    end

    def run
      template = template_exists?(@prefix, get_template_prefixes) ? @prefix : 'run'
      render action: template, locals: { report: @report }
    end

  private

    def find_report
      @prefix = params[:report_name]
      @report_name = "#{@prefix}_report"

      begin
        require(@report_name) unless Module.const_defined?(@report_name.classify)
        @report_class = @report_name.camelize.constantize
      rescue LoadError
        flash[:error] = t(:invalid_report)
        redirect_to action: :index
      end
    end

    def run_report
      @report = @report_class.new(params[:report]).run(self)
    end
<commit_msg>Move report setup to a before_filter so it can be overridden<commit_after>module Compendium
  class ReportsController < ::ApplicationController
    helper Compendium::ReportsHelper

    before_filter :find_report
    before_filter :run_report, only: :run

    def setup
      render locals: { report: setup_report, prefix: @prefix }
    end

    def run
      template = template_exists?(@prefix, get_template_prefixes) ? @prefix : 'run'
      render action: template, locals: { report: @report }
    end

    private

    def find_report
      @prefix = params[:report_name]
      @report_name = "#{@prefix}_report"

      begin
        require(@report_name) unless Module.const_defined?(@report_name.classify)
        @report_class = @report_name.camelize.constantize
      rescue LoadError
        flash[:error] = t(:invalid_report)
        redirect_to action: :index
      end
    end

    def setup_report
      @report_class.new(params[:report] || {})
    end

    def run_report
      @report = @report_class.new(params[:report]).run(self)
    end

{'fraction_non_alphanumeric': 0.09642147117296222, 'fraction_numerical': 0.0, 'mean_word_length': 3.159090909090909, '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': '3624241', 'n_tokens_mistral': 598, 'n_tokens_neox': 582, 'n_words': 140}