2016-04-02 18:10:28 +05:30
|
|
|
class Appearance < ActiveRecord::Base
|
2016-11-03 12:29:30 +05:30
|
|
|
include CacheMarkdownField
|
|
|
|
|
|
|
|
cache_markdown_field :description
|
2018-03-17 18:26:18 +05:30
|
|
|
cache_markdown_field :new_project_guidelines
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
validates :logo, file_size: { maximum: 1.megabyte }
|
|
|
|
validates :header_logo, file_size: { maximum: 1.megabyte }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
validate :single_appearance_row, on: :create
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
mount_uploader :logo, AttachmentUploader
|
|
|
|
mount_uploader :header_logo, AttachmentUploader
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
has_many :uploads, as: :model, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
|
|
|
|
|
|
|
CACHE_KEY = 'current_appearance'.freeze
|
|
|
|
|
|
|
|
after_commit :flush_redis_cache
|
|
|
|
|
|
|
|
def self.current
|
|
|
|
Rails.cache.fetch(CACHE_KEY) { first }
|
|
|
|
end
|
|
|
|
|
|
|
|
def flush_redis_cache
|
|
|
|
Rails.cache.delete(CACHE_KEY)
|
|
|
|
end
|
|
|
|
|
|
|
|
def single_appearance_row
|
|
|
|
if self.class.any?
|
|
|
|
errors.add(:single_appearance_row, 'Only 1 appearances row can exist')
|
|
|
|
end
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|