<commit_before>require 'action_view'

module MAS
  module Frontend
    module Helpers
      module Forms
        module Builders
          class Validation < ::ActionView::Helpers::FormBuilder
            include ActionView::Helpers::TagHelper
            include ActionView::Context

            # TODO partials
            # TODO i18n
            def validation_summary
              content_tag(:ol) do
                errors.map do |error|
                  field = (error[:field] == :base ? "" : "#{error[:field]} ".humanize)
                  content_tag(:li, "#{error[:number]}. #{field}#{error[:message]}")
                end.join.html_safe
              end
            end

            # TODO partials
            # TODO i18n
            def errors_for(object, field)
              content_tag(:ol) do
                errors.select{|hash| hash[:object] == object && hash[:field] == field}.map do |error|
                  field = (error[:field] == :base ? "" : "#{error[:field]} ".humanize)
                  content_tag(:li, "#{error[:number]}. #{field}#{error[:message]}")
                end.join.html_safe
              end
            end

            def validates(*models)
              @error_models = models
            end

            private

            def error_models
              @error_models ||= [object]
            end

            def errors
              return @errors if @errors

              @errors = []
              counter = 1

              # TODO each with index

              error_models.each do |model|
                model.errors.each do |field,message|
                  @errors << {number: counter, object: model, field: field, message: message}
                  counter += 1
                end
              end

              @errors
            end
          end
        end
      end
    end
  end
end

<commit_msg>message generation uses active model<commit_after>require 'action_view'

module MAS
  module Frontend
    module Helpers
      module Forms
        module Builders
          class Validation < ::ActionView::Helpers::FormBuilder
            include ActionView::Helpers::TagHelper
            include ActionView::Context

            # TODO partials
            def validation_summary
              content_tag(:ol) do
                errors.map do |error|
                  content_tag(:li, "#{error[:number]}. #{error[:message]}")
                end.join.html_safe
              end
            end

            # TODO partials
            def errors_for(object, field)
              content_tag(:ol) do
                errors.select{|hash| hash[:object] == object && hash[:field] == field}.map do |error|
                  content_tag(:li, "#{error[:number]}. #{error[:message]}")
                end.join.html_safe
              end
            end

            def validates(*models)
              @error_models = models
            end

            private

            def error_models
              @error_models ||= [object]
            end

            def errors
              return @errors if @errors

              @errors = []
              counter = 1

              # TODO each with index

              error_models.each do |model|
                model.errors.each do |field,message|
                  @errors << {number: counter, object: model, field: field, message: model.errors.full_message(field, message)}
                  counter += 1
                end
              end

              @errors
            end
          end
        end
      end
    end
  end
end


{'fraction_non_alphanumeric': 0.09223437061956827, 'fraction_numerical': 0.00224278104850014, 'mean_word_length': 1.2842509603072982, 'pattern_counts': {'":': 0, '<': 9, '<?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': '526094', 'n_tokens_mistral': 893, 'n_tokens_neox': 843, 'n_words': 229}