<commit_before>module WithAssignments
  extend ActiveSupport::Concern

  included do
    has_many :assignments, dependent: :destroy
  end

  def current_content_for(user)
    assignment_for(user).try(&:solution) ||
      default_content_for(user)
  end

  def files_for(user)
    language
      .directives_sections
      .split_sections(assignment_for(user)&.solution || default_content_for(user))
      .map { |name, content| Mumuki::Laboratory::File.new name, content }
  end

  def interpolate_for(user, field)
    language.interpolate(field, user.interpolations, lambda { |content| replace_content_reference(user, content) })
  end

  def default_content_for(user)
    interpolate_for user, default_content || ''
  end

  def extra_for(user)
    interpolate_for user, extra
  end

  def test_for(user)
    test && interpolate_for(user, test)
  end

  def replace_content_reference(user, interpolee)
    case interpolee
      when /previousContent|previousSolution/
        previous.current_content_for(user)
      when /(solution|content)\[(-?\d*)\]/
        sibling_at($2.to_i).current_content_for(user)
    end
  end

  def messages_for(user)<commit_msg>Removing duplicated logic<commit_after>module WithAssignments
  extend ActiveSupport::Concern

  included do
    has_many :assignments, dependent: :destroy
  end

  def current_content_for(user)
    assignment_for(user)&.solution || default_content_for(user)
  end

  def files_for(user)
    language
      .directives_sections
      .split_sections(current_content_for user)
      .map { |name, content| Mumuki::Laboratory::File.new name, content }
  end

  def interpolate_for(user, field)
    language.interpolate(field, user.interpolations, lambda { |content| replace_content_reference(user, content) })
  end

  def default_content_for(user)
    interpolate_for user, default_content || ''
  end

  def extra_for(user)
    interpolate_for user, extra
  end

  def test_for(user)
    test && interpolate_for(user, test)
  end

  def replace_content_reference(user, interpolee)
    case interpolee
      when /previousContent|previousSolution/
        previous.current_content_for(user)
      when /(solution|content)\[(-?\d*)\]/
        sibling_at($2.to_i).current_content_for(user)
    end
  end

  def messages_for(user)
{'fraction_non_alphanumeric': 0.09488412767818102, 'fraction_numerical': 0.0008745080891998251, 'mean_word_length': 3.9847494553376905, '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': '1443980', 'n_tokens_mistral': 758, 'n_tokens_neox': 720, 'n_words': 145}