<commit_before>module DataMapper
  class Mapper

    # Class representing a relation's attribute within a mapper
    #
    # @abstract
    #
    # @api private
    class Attribute

      Alias = Struct.new(:field, :prefix) {
        include Equalizer.new(:to_sym)

        attr_reader :name

        alias_method :to_sym, :name

        private :field=, :prefix=

        def initialize(field, prefix)
          super
          @name = :"#{prefix}_#{field}"
        end

        def to_s
          name.to_s
        end
      }

      include AbstractType

      include Equalizer.new(:name, :type, :field, :options)

      # Return an aliasd +field_name+ by prefixing +prefix+
      #
      # @example
      #
      #   Attribute.aliased(:title, :songs) # => :songs_title
      #
      # @param [#to_s] field
      #   the field to alias
      #
      # @param [#to_s] prefix
      #   the prefix to use for aliasing
      #
      # @return [Symbol]
      #   the aliased field name
      #
      # @api private
      def self.aliased_field(*args)
        Alias.new(*args)
      end

      # The attribute's name
      #
      # @example
      #
      #   attribute = DataMapper[Person].attributes[:name]
      #   attribute.name
      #
      # @return [Symbol]
      #
      # @api public
      attr_reader :name<commit_msg>Add naive caching of attribute aliases (fixes issue with rbx as a bonus)<commit_after>module DataMapper
  class Mapper

    # Class representing a relation's attribute within a mapper
    #
    # @abstract
    #
    # @api private
    class Attribute

      Alias = Struct.new(:field, :prefix) {
        include Equalizer.new(:name)

        attr_reader :name

        alias_method :to_sym, :name

        private :field=, :prefix=

        CACHE = {}

        def self.build(field, prefix)
          key = "#{field}-#{prefix}"
          CACHE.fetch(key) { CACHE[key] = Alias.new(field, prefix) }
        end

        def initialize(field, prefix)
          super
          @name = :"#{prefix}_#{field}"
        end

        def to_s
          name.to_s
        end
      }

      include AbstractType

      include Equalizer.new(:name, :type, :field, :options)

      # Return an aliasd +field_name+ by prefixing +prefix+
      #
      # @example
      #
      #   Attribute.aliased(:title, :songs) # => :songs_title
      #
      # @param [#to_s] field
      #   the field to alias
      #
      # @param [#to_s] prefix
      #   the prefix to use for aliasing
      #
      # @return [Symbol]
      #   the aliased field name
      #
      # @api private
      def self.aliased_field(*args)
        Alias.build(*args)
      end

      # The attribute's name
      #
      # @example
      #
      #   attribute = DataMapper[Person].attributes[:name]
      #   attribute.name
      #
      # @return [Symbol]
      #
      # @api public
      attr_reader :name
{'fraction_non_alphanumeric': 0.10346020761245675, 'fraction_numerical': 0.0, 'mean_word_length': 1.7018691588785047, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4022809', 'n_tokens_mistral': 901, 'n_tokens_neox': 860, 'n_words': 222}