<commit_before>module Commentable
  extend ActiveSupport::Concern

  def index
    @commentables = @search_terms.present? ? commentable_model.search(@search_terms) : commentable_model.all
    @commentables = @commentables.tagged_with(@tag_filter) if @tag_filter
    @commentables = @commentables.page(params[:page]).for_render.send("sort_by_#{@current_order}")
    @tag_cloud = tag_cloud

    set_commentable_votes(@commentables)
    set_commentables_instance
  end

  def show
    set_commentable_votes(commentable)
    @root_comments = commentable.comments.roots.recent.page(params[:page]).per(10).for_render
    @comments = @root_comments.inject([]){|all, root| all + Comment.descendants_of(root).for_render}
    @all_visible_comments = @root_comments + @comments

    set_comment_flags(@all_visible_comments)
    set_commentable_instance
  end

  def new
    @commentable = commentable_model.new
    set_commentable_instance
    load_featured_tags
  end

  def create
    @commentable = commentable_model.new(strong_params)
    @commentable.author = current_user

    if @commentable.save_with_captcha
      track_event
      redirect_to @commentable, notice: t('flash.actions.create.notice', resource_name: "#{commentable_name.capitalize}")
    else
      load_featured_tags
      set_commentable_instance
      render :new
    end
  end

  def edit
    load_featured_tags
  end

  def update
    commentable.assign_attributes(strong_params)
    if commentable.save_with_captcha
      redirect_to commentable, notice: t('flash.actions.update.notice', resource_name: "#{commentable_name.capitalize}")
    else
      load_featured_tags
      set_commentable_instance
      render :edit
    end
  end

  private
    def commentable
      @commentable ||= instance_variable_get("@#{commentable_name}")
    end

    def commentable_model
      @commentable_model ||= commentable_name.capitalize.constantize
    end

    def commentable_name
      controller_name.singularize
    end

    def set_commentable_instance
      instance_variable_set("@#{commentable_name}", @commentable)
    end

    def set_commentables_instance
      instance_variable_set("@#{commentable_name.pluralize}", @commentables)
    end

    def set_commentable_votes(instance)
      send("set_#{commentable_name}_votes", instance)
    end<commit_msg>adds consistency and speed to auxiliary methods<commit_after>module Commentable
  extend ActiveSupport::Concern

  def index
    @commentables = @search_terms.present? ? commentable_model.search(@search_terms) : commentable_model.all
    @commentables = @commentables.tagged_with(@tag_filter) if @tag_filter
    @commentables = @commentables.page(params[:page]).for_render.send("sort_by_#{@current_order}")
    @tag_cloud = tag_cloud

    set_commentable_votes(@commentables)
    set_commentables_instance
  end

  def show
    set_commentable_votes(commentable)
    @root_comments = commentable.comments.roots.recent.page(params[:page]).per(10).for_render
    @comments = @root_comments.inject([]){|all, root| all + Comment.descendants_of(root).for_render}
    @all_visible_comments = @root_comments + @comments

    set_comment_flags(@all_visible_comments)
    set_commentable_instance
  end

  def new
    @commentable = commentable_model.new
    set_commentable_instance
    load_featured_tags
  end

  def create
    @commentable = commentable_model.new(strong_params)
    @commentable.author = current_user

    if @commentable.save_with_captcha
      track_event
      redirect_to @commentable, notice: t('flash.actions.create.notice', resource_name: "#{commentable_name.capitalize}")
    else
      load_featured_tags
      set_commentable_instance
      render :new
    end
  end

  def edit
    load_featured_tags
  end

  def update
    commentable.assign_attributes(strong_params)
    if commentable.save_with_captcha
      redirect_to commentable, notice: t('flash.actions.update.notice', resource_name: "#{commentable_name.capitalize}")
    else
      load_featured_tags
      set_commentable_instance
      render :edit
    end
  end

  private
    def commentable
      @commentable ||= instance_variable_get("@#{commentable_name}")
    end

    def commentable_name
      @commentable_name ||= controller_name.singularize
    end

    def commentable_model
      @commentable_model ||= commentable_name.capitalize.constantize
    end

    def set_commentable_instance
      instance_variable_set("@#{commentable_name}", @commentable)
    end

    def set_commentables_instance
      instance_variable_set("@#{commentable_name.pluralize}", @commentables)
    end

    def set_commentable_votes(instance)
      send("set_#{commentable_name}_votes", instance)
    end
{'fraction_non_alphanumeric': 0.08414789630259244, 'fraction_numerical': 0.0008499787505312367, 'mean_word_length': 4.201104972375691, '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': '1443957', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1430, 'n_words': 242}