<commit_before>##
# Adds breadcrumbs for each action
module Admin
  module Breadcrumbs
    extend ActiveSupport::Concern

    included do
      before_action :add_breadcrumbs
    end

    def add_breadcrumbs
      breadcrumb_for "index" # base

      breadcrumb_for action_name unless action_name == "index"
    end

    ##
    # base name (singular for breadcrumbs)
    def breadcrumb_base
      controller_name.singularize
    end

    def breadcrumbs_plural
      breadcrumb_base.pluralize
    end

    private

    ##
    # @param action [String] name of the action
    #   to render breadcrumbs for
    def breadcrumb_for(action)
      case action
      when "index"
        add_breadcrumb(
          I18n.t(
            "activerecord.models.#{breadcrumb_base}"
          ).pluralize,
          send("admin_#{breadcrumbs_plural}_path")
        )
      when "new"
        add_breadcrumb(
          I18n.t(
            "views.#{breadcrumbs_plural}.new"
          ),
          send("new_admin_#{breadcrumb_base}_path")
        )
      when "create"
        breadcrumb_for "new"
      when "show"
        add_breadcrumb(
          resource,
          send("admin_#{breadcrumb_base}_path", resource)
        )
      when "edit"
        breadcrumb_for "show"

        add_breadcrumb(
          I18n.t("views.#{breadcrumb_base.pluralize}.edit"),
          send("edit_admin_#{breadcrumb_base}_path")
        )
      when "update"
        breadcrumb_for "edit"
      end
    end
  end
end<commit_msg>allow deeper nesting of breadcrumbs<commit_after>##
# Adds breadcrumbs for each action
module Admin
  module Breadcrumbs
    extend ActiveSupport::Concern

    included do
      before_action :add_breadcrumbs
    end

    def add_breadcrumbs
      breadcrumb_for "index" # base

      breadcrumb_for action_name unless action_name == "index"
    end

    ##
    # @return [String] base name (singular)
    #   based on controller's name by default
    def breadcrumb_base
      controller_name.singularize
    end

    def breadcrumbs_plural
      breadcrumb_base.pluralize
    end
    
    ##
    # @return [String] base path to
    #   generate links
    def breadcrumbs_base_path
      breadcrumb_base
    end

    private

    ##
    # @param action [String] name of the action
    #   to render breadcrumbs for
    def breadcrumb_for(action)
      case action
      when "index"
        add_breadcrumb(
          I18n.t(
            "activerecord.models.#{breadcrumb_base}"
          ).pluralize,
          send("admin_#{breadcrumbs_base_path.pluralize}_path")
        )
      when "new"
        add_breadcrumb(
          I18n.t(
            "views.#{breadcrumbs_plural}.new"
          ),
          send("new_admin_#{breadcrumbs_base_path}_path")
        )
      when "create"
        breadcrumb_for "new"
      when "show"
        add_breadcrumb(
          resource,
          send("admin_#{breadcrumbs_base_path}_path", resource)
        )
      when "edit"
        breadcrumb_for "show"

        add_breadcrumb(
          I18n.t("views.#{breadcrumb_base.pluralize}.edit"),
          send("edit_admin_#{breadcrumbs_base_path}_path")
        )
      when "update"
        breadcrumb_for "edit"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08035991312441824, 'fraction_numerical': 0.003723239218119764, 'mean_word_length': 2.0704761904761906, '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': '7477793', 'n_tokens_mistral': 1044, 'n_tokens_neox': 1043, 'n_words': 210}