<commit_before>class Course::Material::Controller < Course::ComponentController
  load_and_authorize_resource :folder, through: :course, through_association: :material_folders,
                                       class: Course::Material::Folder.name

  before_action :check_component
  before_action :add_folder_breadcrumb

  private

  # @return [Course::MaterialsComponent|nil] The materials component or nil if disabled.
  def component
    current_component_host[:course_materials_component]
  end
  helper_method :component

  # Ensure that the component is enabled.
  #
  # @raise [Coursemology::ComponentNotFoundError] When the component is disabled.
  def check_component
    fail ComponentNotFoundError unless component
  end

  def add_folder_breadcrumb
    folders_chain = @folder.ancestors.reverse << @folder
    root_folder = folders_chain.shift

    add_breadcrumb component.settings.title || t('course.material.sidebar_title'),
                   course_material_folder_path(current_course, root_folder)
    folders_chain.each do |folder|
      add_breadcrumb folder.name, course_material_folder_path(current_course, folder)
    end
  end
end<commit_msg>Factor out root folder name to a method<commit_after>class Course::Material::Controller < Course::ComponentController
  load_and_authorize_resource :folder, through: :course, through_association: :material_folders,
                                       class: Course::Material::Folder.name

  before_action :check_component
  before_action :add_folder_breadcrumb

  private

  # @return [Course::MaterialsComponent|nil] The materials component or nil if disabled.
  def component
    current_component_host[:course_materials_component]
  end
  helper_method :component

  # Ensure that the component is enabled.
  #
  # @raise [Coursemology::ComponentNotFoundError] When the component is disabled.
  def check_component
    fail ComponentNotFoundError unless component
  end

  def root_folder_name
    component.settings.title || t('course.material.sidebar_title')
  end

  def add_folder_breadcrumb
    folders_chain = @folder.ancestors.reverse << @folder
    root_folder = folders_chain.shift

    add_breadcrumb root_folder_name, course_material_folder_path(current_course, root_folder)
    folders_chain.each do |folder|
      add_breadcrumb folder.name, course_material_folder_path(current_course, folder)
    end
  end
end
{'fraction_non_alphanumeric': 0.06577851790174855, 'fraction_numerical': 0.0, 'mean_word_length': 4.387892376681615, 'pattern_counts': {'":': 0, '<': 9, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2130985', 'n_tokens_mistral': 669, 'n_tokens_neox': 646, 'n_words': 156}