<commit_before>class Topic < ActiveRecord::Base
  include ContentIdentifiable
  validate :path_can_be_set_once
  validate :path_format

  has_many :topic_sections, -> { order(position: :asc) }
  has_many :guides, through: :topic_sections

  def ready_to_publish?
    persisted?
  end

  def latest_edition
    self
  end

  def update_type
    'major'
  end

  # TODO: We have topics.path and guides.slug. We should standardise with
  # the most commonly used term in other apps.
  def slug
    path
  end

  def guide_content_ids
    topic_sections.map do |topic_section|
      topic_section.guides.map(&:content_id)
    end.flatten
  end

  private

  def path_can_be_set_once
    if persisted? && path != path_was
      errors.add(:path, "can not be changed")
    end
  end

  def path_format
    if !path.to_s.match(/\A\/service-manual\//)
      errors.add(:path, "must be present and start with '/service-manual/'")<commit_msg>Refactor guide_content_ids to use guides has_many<commit_after>class Topic < ActiveRecord::Base
  include ContentIdentifiable
  validate :path_can_be_set_once
  validate :path_format

  has_many :topic_sections, -> { order(position: :asc) }
  has_many :guides, through: :topic_sections

  def ready_to_publish?
    persisted?
  end

  def latest_edition
    self
  end

  def update_type
    'major'
  end

  # TODO: We have topics.path and guides.slug. We should standardise with
  # the most commonly used term in other apps.
  def slug
    path
  end

  def guide_content_ids
    guides.pluck(:content_id).uniq
  end

  private

  def path_can_be_set_once
    if persisted? && path != path_was
      errors.add(:path, "can not be changed")
    end
  end

  def path_format
    if !path.to_s.match(/\A\/service-manual\//)
      errors.add(:path, "must be present and start with '/service-manual/'")
{'fraction_non_alphanumeric': 0.08460698689956332, 'fraction_numerical': 0.0, 'mean_word_length': 3.2430555555555554, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2713943', 'n_tokens_mistral': 623, 'n_tokens_neox': 599, 'n_words': 170}