<commit_before>module ValidatesTimeliness
  module AttributeMethods
    extend ActiveSupport::Concern

    included do
      class_attribute :timeliness_validated_attributes
      self.timeliness_validated_attributes = []
    end

    module ClassMethods

      public
      # Override in ORM shim
      def timeliness_attribute_timezone_aware?(attr_name)
        false
      end

      # Override in ORM shim
      def timeliness_attribute_type(attr_name)
        :datetime
      end

      def define_timeliness_methods(before_type_cast=false)
        return if timeliness_validated_attributes.blank?
        timeliness_validated_attributes.each do |attr_name|
          define_attribute_timeliness_methods(attr_name, before_type_cast)
        end
      end

      def generated_timeliness_methods
        @generated_timeliness_methods ||= Module.new { |m| 
          extend Mutex_m
        }.tap { |mod| include mod }
      end

      def undefine_attribute_methods
        super.tap { undefine_timeliness_attribute_methods }
      end

      def undefine_timeliness_attribute_methods
        generated_timeliness_methods.synchronize do
          generated_timeliness_methods.module_eval do
            instance_methods.each { |m| undef_method(m) } 
          end
        end
      end

      protected

      def define_attribute_timeliness_methods(attr_name, before_type_cast=false)
        define_timeliness_write_method(attr_name)
        define_timeliness_before_type_cast_method(attr_name) if before_type_cast
      end

      def define_timeliness_write_method(attr_name)
        generated_timeliness_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
          def #{attr_name}=(value)
            write_timeliness_attribute('#{attr_name}', value)
          end
        STR
      end

      def define_timeliness_before_type_cast_method(attr_name)
        generated_timeliness_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
          def #{attr_name}_before_type_cast
            read_timeliness_attribute_before_type_cast('#{attr_name}')
          end
        STR
      end
    end

    def write_timeliness_attribute(attr_name, value)
      @timeliness_cache ||= {}
      @timeliness_cache[attr_name] = value

      if ValidatesTimeliness.use_plugin_parser
        timezone = :current if self.class.timeliness_attribute_timezone_aware?(attr_name)
        value = Timeliness::Parser.parse(value, self.class.timeliness_attribute_type(attr_name), :zone => timezone)
      end
<commit_msg>Return date if date type<commit_after>module ValidatesTimeliness
  module AttributeMethods
    extend ActiveSupport::Concern

    included do
      class_attribute :timeliness_validated_attributes
      self.timeliness_validated_attributes = []
    end

    module ClassMethods

      public
      # Override in ORM shim
      def timeliness_attribute_timezone_aware?(attr_name)
        false
      end

      # Override in ORM shim
      def timeliness_attribute_type(attr_name)
        :datetime
      end

      def define_timeliness_methods(before_type_cast=false)
        return if timeliness_validated_attributes.blank?
        timeliness_validated_attributes.each do |attr_name|
          define_attribute_timeliness_methods(attr_name, before_type_cast)
        end
      end

      def generated_timeliness_methods
        @generated_timeliness_methods ||= Module.new { |m| 
          extend Mutex_m
        }.tap { |mod| include mod }
      end

      def undefine_attribute_methods
        super.tap { undefine_timeliness_attribute_methods }
      end

      def undefine_timeliness_attribute_methods
        generated_timeliness_methods.synchronize do
          generated_timeliness_methods.module_eval do
            instance_methods.each { |m| undef_method(m) } 
          end
        end
      end

      protected

      def define_attribute_timeliness_methods(attr_name, before_type_cast=false)
        define_timeliness_write_method(attr_name)
        define_timeliness_before_type_cast_method(attr_name) if before_type_cast
      end

      def define_timeliness_write_method(attr_name)
        generated_timeliness_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
          def #{attr_name}=(value)
            write_timeliness_attribute('#{attr_name}', value)
          end
        STR
      end

      def define_timeliness_before_type_cast_method(attr_name)
        generated_timeliness_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
          def #{attr_name}_before_type_cast
            read_timeliness_attribute_before_type_cast('#{attr_name}')
          end
        STR
      end
    end

    def write_timeliness_attribute(attr_name, value)
      @timeliness_cache ||= {}
      @timeliness_cache[attr_name] = value

      if ValidatesTimeliness.use_plugin_parser
        type = self.class.timeliness_attribute_type(attr_name)
        timezone = :current if self.class.timeliness_attribute_timezone_aware?(attr_name)
        value = Timeliness::Parser.parse(value, type, :zone => timezone)
        value = value.to_date if value && type == :date
      end

{'fraction_non_alphanumeric': 0.056963268513062264, 'fraction_numerical': 0.000785700255352583, 'mean_word_length': 2.8989280245022973, 'pattern_counts': {'":': 0, '<': 11, '<?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': '3391566', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1494, 'n_words': 266}