appearance.rb 849 Bytes
Newer Older
1 2
# frozen_string_literal: true

3
class Appearance < ActiveRecord::Base
4
  include CacheableAttributes
5
  include CacheMarkdownField
6
  include ObjectStorage::BackgroundMove
Jan Provaznik's avatar
Jan Provaznik committed
7
  include WithUploads
8 9

  cache_markdown_field :description
10
  cache_markdown_field :new_project_guidelines
11

12 13 14
  validates :logo,        file_size: { maximum: 1.megabyte }
  validates :header_logo, file_size: { maximum: 1.megabyte }

15 16
  validate :single_appearance_row, on: :create

17 18
  mount_uploader :logo,         AttachmentUploader
  mount_uploader :header_logo,  AttachmentUploader
19
  mount_uploader :favicon,      FaviconUploader
20

21 22 23
  # Overrides CacheableAttributes.current_without_cache
  def self.current_without_cache
    first
24 25 26 27 28 29 30
  end

  def single_appearance_row
    if self.class.any?
      errors.add(:single_appearance_row, 'Only 1 appearances row can exist')
    end
  end
31
end