debian-mirror-gitlab/app/models/concerns/has_wiki_page_slug_attributes.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
694 B
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# 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