<commit_before>module FlexibleDate
  def flexible_date(*params)
    options, fields = params.pop, params
    format = options[:format]
    fields.each do |field|
      validate :flexible_date_validations

      define_method "#{field}_flex" do
        self.send("#{field}").strftime(format)
      end

      lambda {
        define_method "#{field}_flex=" do |value|
          begin
            self.send("#{field}=", Date.strptime(value, format))
          rescue ArgumentError
            @flexible_date_errors ||= {}
            @flexible_date_errors["#{field}".to_sym] = 'invalid'
            @flexible_date_errors["#{field}_flex".to_sym] = 'invalid'
          end
        end

        define_method :flexible_date_validations do
          if @flexible_date_errors
            @flexible_date_errors.each do |field, message|
              errors.add(field, message)
            end
          end
        end
      }.call
    end
  end
end

ActiveRecord::Base.extend(FlexibleDate)
<commit_msg>removed unnecessary lambda<commit_after>module FlexibleDate
  def flexible_date(*params)
    options, fields = params.pop, params
    format = options[:format]
    fields.each do |field|
      validate :flexible_date_validations

      define_method "#{field}_flex" do
        self.send("#{field}").strftime(format)
      end

      define_method "#{field}_flex=" do |value|
        begin
          self.send("#{field}=", Date.strptime(value, format))
        rescue ArgumentError
          @flexible_date_errors ||= {}
          @flexible_date_errors["#{field}".to_sym] = 'invalid'
          @flexible_date_errors["#{field}_flex".to_sym] = 'invalid'
        end
      end

      define_method :flexible_date_validations do
        if @flexible_date_errors
          @flexible_date_errors.each do |field, message|
            errors.add(field, message)
          end
        end
      end
    end
  end
end

ActiveRecord::Base.extend(FlexibleDate)

{'fraction_non_alphanumeric': 0.1065362840967576, 'fraction_numerical': 0.0, 'mean_word_length': 2.4285714285714284, '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': '1161891', 'n_tokens_mistral': 580, 'n_tokens_neox': 575, 'n_words': 114}