<commit_before>class SiteCustomization::Page < ActiveRecord::Base
  VALID_STATUSES = %w[draft published]
  has_many :cards, class_name: "Widget::Card", foreign_key: "site_customization_page_id"

  translates :title,       touch: true
  translates :subtitle,    touch: true
  translates :content,     touch: true
  include Globalizable

  validates_translation :title, presence: true
  validates :slug, presence: true,
                   uniqueness: { case_sensitive: false },
                   format: { with: /\A[0-9a-zA-Z\-_]*\Z/, message: :slug_format }
  validates :status, presence: true, inclusion: { in: VALID_STATUSES }

  scope :published, -> { where(status: "published").order("id DESC") }
  scope :with_more_info_flag, -> { where(status: "published",
                                   more_info_flag: true).order("id ASC") }
  scope :with_same_locale, -> { joins(:translations)
                                .where("site_customization_page_translations.locale": I18n.locale) }

  def url
    "/#{slug}"
  end
end<commit_msg>Refactor scopes on site customization page model<commit_after>class SiteCustomization::Page < ActiveRecord::Base
  VALID_STATUSES = %w[draft published]
  has_many :cards, class_name: "Widget::Card", foreign_key: "site_customization_page_id"

  translates :title,       touch: true
  translates :subtitle,    touch: true
  translates :content,     touch: true
  include Globalizable

  validates_translation :title, presence: true
  validates :slug, presence: true,
                   uniqueness: { case_sensitive: false },
                   format: { with: /\A[0-9a-zA-Z\-_]*\Z/, message: :slug_format }
  validates :status, presence: true, inclusion: { in: VALID_STATUSES }

  scope :published, -> { where(status: "published").sort_desc }
  scope :sort_asc, -> { order("id ASC") }
  scope :sort_desc, -> { order("id DESC") }
  scope :with_more_info_flag, -> { where(status: "published", more_info_flag: true).sort_asc }
  scope :with_same_locale, -> { joins(:translations).locale }
  scope :locale, ->  { where("site_customization_page_translations.locale": I18n.locale) }

  def url
    "/#{slug}"
  end
end
{'fraction_non_alphanumeric': 0.1275011633317822, 'fraction_numerical': 0.0037226617031177293, 'mean_word_length': 3.4329896907216493, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3730722', 'n_tokens_mistral': 688, 'n_tokens_neox': 665, 'n_words': 155}