<commit_before>module ActiveAdmin
  class Resource

    module Naming

      # Returns a name used to uniquely identify this resource
      # this should be an instance of ActiveAdmin:Resource::Name, which responds to
      # #singular, #plural, #route_key, #human etc.
      def resource_name
        @resource_name ||= begin
          as = @options[:as].gsub /\s/, '' if @options[:as]

          if as || !resource_class.respond_to?(:model_name)
            Name.new resource_class, as
          else
            Name.new resource_class
          end
        end
      end

      # Returns the name to call this resource such as "Bank Account"
      def resource_label
        resource_name.translate count: 1,
          default: resource_name.to_s.gsub('::', ' ').titleize
      end

      # Returns the plural version of this resource such as "Bank Accounts"
      def plural_resource_label(options = {})
        defaults = {count:   Helpers::I18n::PLURAL_MANY_COUNT,
                    default: resource_label.pluralize.titleize}
        resource_name.translate defaults.merge options
      end

      # Forms use the model's original `param_key`, so we can't use our
      # custom `resource_name` when the model's been renamed in ActiveAdmin.
      def param_key
        if resource_class.respond_to? :model_name
          resource_class.model_name.param_key
        else
          resource_name.param_key
        end
      end
    end

    # A subclass of ActiveModel::Name which supports the different APIs presented
    # in Rails < 3.1 and > 3.1.
    class Name < ActiveModel::Name

      delegate :hash, to: :to_str

      def initialize(klass, name = nil)
        if ActiveModel::Name.instance_method(:initialize).arity == 1
          super(proxy_for_initializer(klass, name))
        else
          super(klass, nil, name)
        end
      end

      def translate(options = {})
        I18n.t i18n_key, {scope: [:activerecord, :models]}.merge(options)
      end

      def proxy_for_initializer(klass, name)
        return klass unless name
        return StringClassProxy.new(klass, name) if klass

        StringProxy.new(name)
      end

      def route_key
        plural
      end

      def eql?(other)
        to_str.eql?(other.to_str)
      end

      class StringProxy
        def initialize(name)
          @name = name
        end

        def name
          @name
        end
      end

      class StringClassProxy < StringProxy
        delegate :lookup_ancestors, :i18n_scope, to: :@klass

        def initialize(klass, name)
          @klass = klass || name
          super(name)
        end
      end

    end

  end
end<commit_msg>remove Rails 3.1 ActiveModel::Name compatibility layer<commit_after>module ActiveAdmin
  class Resource

    module Naming
      def resource_name
        @resource_name ||= begin
          as = @options[:as].gsub /\s/, '' if @options[:as]

          if as || !resource_class.respond_to?(:model_name)
            Name.new resource_class, as
          else
            Name.new resource_class
          end
        end
      end

      # Returns the name to call this resource such as "Bank Account"
      def resource_label
        resource_name.translate count: 1,
          default: resource_name.to_s.gsub('::', ' ').titleize
      end

      # Returns the plural version of this resource such as "Bank Accounts"
      def plural_resource_label(options = {})
        defaults = {count:   Helpers::I18n::PLURAL_MANY_COUNT,
                    default: resource_label.pluralize.titleize}
        resource_name.translate defaults.merge options
      end

      # Forms use the model's original `param_key`, so we can't use our
      # custom `resource_name` when the model's been renamed in ActiveAdmin.
      def param_key
        if resource_class.respond_to? :model_name
          resource_class.model_name.param_key
        else
          resource_name.param_key
        end
      end
    end

    class Name < ActiveModel::Name
      delegate :hash, to: :to_str

      def initialize(klass, name = nil)
        super(klass, nil, name)
      end

      def translate(options = {})
        I18n.t i18n_key, {scope: [:activerecord, :models]}.merge(options)
      end

      def route_key
        plural
      end

      def eql?(other)
        to_str.eql?(other.to_str)
      end
    end

  end
end
{'fraction_non_alphanumeric': 0.07766323024054983, 'fraction_numerical': 0.005269186712485682, 'mean_word_length': 2.0595655220742817, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, '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': '7641246', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1232, 'n_words': 361}