Welcome to mirror list, hosted at ThFree Co, Russian Federation.

has_wiki_page_slug_attributes.rb « concerns « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3335eccbaf68cb07ebceb4bd594b3cb794ea65e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

module HasWikiPageSlugAttributes
  extend ActiveSupport::Concern

  included do
    validates :slug, uniqueness: { scope: meta_foreign_key }
    validates :slug, length: { maximum: 2048 }, allow_nil: false
    validates :canonical, uniqueness: {
          scope: meta_foreign_key,
          if: :canonical?,
          message: 'Only one slug can be canonical per wiki metadata record'
    }

    scope :canonical, -> { where(canonical: true) }

    def update_columns(attrs = {})
      super(attrs.reverse_merge(updated_at: Time.current.utc))
    end
  end

  def self.update_all(attrs = {})
    super(attrs.reverse_merge(updated_at: Time.current.utc))
  end
end