<commit_before>#encoding: utf-8
module Formitas
  # Method object for message translation
  class MessageTransformer < Aequitas::MessageTransformer
    include Immutable
    
    # Transforms the specified Violation to an translated error message string
    #
    # @param [Violation] violation
    # The Violation to transform
    #
    # @return [String]
    # The transformed message
    #
    # @api private
    #
    def self.transform(violation)
      klass = [:length_between,:blank].include?(violation.type) ? Aequitas : self
      klass.new(violation).translation
    end

    # Result of translation
    #
    # @return [String]
    # The translated message
    #
    # @api private
    #
    attr_reader :translation

  private
    
    # Initialize message translation object and calculates translation
    #
    # @param [Violation] violation
    # The Violation to transform
    #
    # @return [undefined]
    # The transformed message
    #
    # @api private
    #
    def initialize(violation)
      @violation = violation
      @translation = translate
    end

    # Translate violation error
    #
    # @return [String]
    # The translated message
    #
    # @api private
    #
    def translate
      ::I18n.translate(violation_type, options.merge(violation_info))
    end
    memoize :translate

    # Return violation type
    #
    # @return [String]
    # The violation type
    #
    # @api private
    #
    def violation_type
      violation.type
    end

    # Return violation info
    #
    # @return [Hash]
    # The violation info
    #
    # @api private
    #
    def violation_info
      violation.info
    end

    # Options for translation scope
    #
    # @return [Hash]
    #
    # @api private
    #
    def options
      {
        :attribute => attribute,
        :value     => value,
        :scope     => scope
      }
    end
    memoize :options

    # Return violation
    #
    # @return [Violation]
    #
    # @api private
    #
    attr_reader :violation

    # Return violation resource
    #
    # @return [Resource]
    #
    # @api private
    #
    def resource
      violation.resource
    end

    # Return model name
    #
    # @return [String]
    #
    # @api private
    #
    def model_name
      resource.class.name.split('::').last.downcase
    end
    memoize :model_name

    # Return attribute name
    #
    # @return [String]
    #
    # @api private
    #
    def attribute_name
      violation.attribute_name
    end

    # Return default scope
    #
    # @return [Array<String>]
    #
    # @api private
    #
    def default_scope
      [model_name,attribute_name]
    end
    memoize :default_scope

    # Return validation attribute value
    #
    # @return [String]
    #
    # @api private
    #
    def value
      resource.validation_attribute_value(attribute_name)
    end
    memoize :value

    # Return base scope
    #
    # @return [Array<String>]
    #
    # @api private
    #
    attr_reader :base_scope
    
    # Return translation key
    #<commit_msg>Fix wrong replacing of base_scope method with attr_reader<commit_after>#encoding: utf-8
module Formitas
  # Method object for message translation
  class MessageTransformer < Aequitas::MessageTransformer
    include Immutable
    
    # Transforms the specified Violation to an translated error message string
    #
    # @param [Violation] violation
    # The Violation to transform
    #
    # @return [String]
    # The transformed message
    #
    # @api private
    #
    def self.transform(violation)
      klass = [:length_between,:blank].include?(violation.type) ? Aequitas : self
      klass.new(violation).translation
    end

    # Result of translation
    #
    # @return [String]
    # The translated message
    #
    # @api private
    #
    attr_reader :translation

  private
    
    # Initialize message translation object and calculates translation
    #
    # @param [Violation] violation
    # The Violation to transform
    #
    # @return [undefined]
    # The transformed message
    #
    # @api private
    #
    def initialize(violation)
      @violation = violation
      @translation = translate
    end

    # Translate violation error
    #
    # @return [String]
    # The translated message
    #
    # @api private
    #
    def translate
      ::I18n.translate(violation_type, options.merge(violation_info))
    end
    memoize :translate

    # Return violation type
    #
    # @return [String]
    # The violation type
    #
    # @api private
    #
    def violation_type
      violation.type
    end

    # Return violation info
    #
    # @return [Hash]
    # The violation info
    #
    # @api private
    #
    def violation_info
      violation.info
    end

    # Options for translation scope
    #
    # @return [Hash]
    #
    # @api private
    #
    def options
      {
        :attribute => attribute,
        :value     => value,
        :scope     => scope
      }
    end
    memoize :options

    # Return violation
    #
    # @return [Violation]
    #
    # @api private
    #
    attr_reader :violation

    # Return violation resource
    #
    # @return [Resource]
    #
    # @api private
    #
    def resource
      violation.resource
    end

    # Return model name
    #
    # @return [String]
    #
    # @api private
    #
    def model_name
      resource.class.name.split('::').last.downcase
    end
    memoize :model_name

    # Return attribute name
    #
    # @return [String]
    #
    # @api private
    #
    def attribute_name
      violation.attribute_name
    end

    # Return default scope
    #
    # @return [Array<String>]
    #
    # @api private
    #
    def default_scope
      [model_name,attribute_name]
    end
    memoize :default_scope

    # Return validation attribute value
    #
    # @return [String]
    #
    # @api private
    #
    def value
      resource.validation_attribute_value(attribute_name)
    end
    memoize :value

    # Return base scope
    #
    # @return [Array<String>]
    #
    # @api private
    def base_scope
      default_scope
    end
    
    # Return translation key
    #
{'fraction_non_alphanumeric': 0.08115565654926149, 'fraction_numerical': 0.0009738678785911378, 'mean_word_length': 1.9811320754716981, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '6797036', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1813, 'n_words': 475}