<commit_before>class Page < ActiveRecord::Base
  extend FriendlyId
  has_paper_trail

  enum follow_up_plan: [:with_liquid, :with_page] # todo - :with_link

  belongs_to :language
  belongs_to :campaign # Note that some pages do not necessarily belong to campaigns
  belongs_to :liquid_layout
  belongs_to :follow_up_page, class_name: 'Page'
  belongs_to :follow_up_liquid_layout, class_name: 'LiquidLayout'
  belongs_to :primary_image, class_name: 'Image'

  has_many :tags, through: :pages_tags
  has_many :actions
  has_many :pages_tags, dependent: :destroy
  has_many :images,     dependent: :destroy
  has_many :links,      dependent: :destroy

  validates :title, presence: true, uniqueness: true
  validates :liquid_layout, presence: true
  validate  :primary_image_is_owned

  after_save :switch_plugins

  friendly_id :title, use: [:finders, :slugged]

  def liquid_data
    attributes.merge(link_list: links.map(&:attributes))
  end

  def plugins
    Plugins.registered.map do |plugin_class|
      plugin_class.where(page_id: id).to_a
    end.flatten.sort_by(&:created_at)
  end

  def shares
    [Share::Facebook, Share::Twitter, Share::Email].inject([]) do |variations, share_class|
      variations += share_class.where(page_id: id)
    end
  end

  def image_to_display
    primary_image || images.first
  end

  def meta_tags
    tags.map {|tag| tag.name.downcase}
  end

  private

  def switch_plugins
    if changed.include?("liquid_layout_id")
      PagePluginSwitcher.new(self).switch(liquid_layout)
    end
  end

  def primary_image_is_owned
    unless primary_image_id.blank? || images.map(&:id).include?(primary_image_id)
      errors.add(:primary_image_id, "is not one of the page's images")
    end
  end
end
<commit_msg>Getting tag names and plugin names into meta tags.<commit_after>class Page < ActiveRecord::Base
  extend FriendlyId
  has_paper_trail

  enum follow_up_plan: [:with_liquid, :with_page] # todo - :with_link

  belongs_to :language
  belongs_to :campaign # Note that some pages do not necessarily belong to campaigns
  belongs_to :liquid_layout
  belongs_to :follow_up_page, class_name: 'Page'
  belongs_to :follow_up_liquid_layout, class_name: 'LiquidLayout'
  belongs_to :primary_image, class_name: 'Image'

  has_many :tags, through: :pages_tags
  has_many :actions
  has_many :pages_tags, dependent: :destroy
  has_many :images,     dependent: :destroy
  has_many :links,      dependent: :destroy

  validates :title, presence: true, uniqueness: true
  validates :liquid_layout, presence: true
  validate  :primary_image_is_owned

  after_save :switch_plugins

  friendly_id :title, use: [:finders, :slugged]

  def liquid_data
    attributes.merge(link_list: links.map(&:attributes))
  end

  def plugins
    Plugins.registered.map do |plugin_class|
      plugin_class.where(page_id: id).to_a
    end.flatten.sort_by(&:created_at)
  end

  def plugin_names
    plugins.map { |plugin| plugin.model_name.name.split('::')[1].downcase }
  end

  def tag_names
    tags.map { |tag| tag.name.downcase }
  end

  def shares
    [Share::Facebook, Share::Twitter, Share::Email].inject([]) do |variations, share_class|
      variations += share_class.where(page_id: id)
    end
  end

  def image_to_display
    primary_image || images.first
  end

  def meta_tags
    tag_names << plugin_names
  end

  private

  def switch_plugins
    if changed.include?("liquid_layout_id")
      PagePluginSwitcher.new(self).switch(liquid_layout)
    end
  end

  def primary_image_is_owned
    unless primary_image_id.blank? || images.map(&:id).include?(primary_image_id)
      errors.add(:primary_image_id, "is not one of the page's images")
    end
  end
end

{'fraction_non_alphanumeric': 0.0921409214092141, 'fraction_numerical': 0.00027100271002710027, 'mean_word_length': 4.235460992907801, 'pattern_counts': {'":': 0, '<': 7, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3696409', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1220, 'n_words': 297}