2016-02-22 14:49:16 -05:00
|
|
|
class Appearance < ActiveRecord::Base
|
2016-10-06 17:17:11 -04:00
|
|
|
include CacheMarkdownField
|
|
|
|
|
|
|
|
cache_markdown_field :description
|
2017-11-22 08:48:38 -05:00
|
|
|
cache_markdown_field :new_project_guidelines
|
2016-10-06 17:17:11 -04:00
|
|
|
|
2016-02-22 14:49:16 -05:00
|
|
|
validates :logo, file_size: { maximum: 1.megabyte }
|
|
|
|
validates :header_logo, file_size: { maximum: 1.megabyte }
|
|
|
|
|
2017-08-09 10:41:51 -04:00
|
|
|
validate :single_appearance_row, on: :create
|
|
|
|
|
2016-02-22 14:49:16 -05:00
|
|
|
mount_uploader :logo, AttachmentUploader
|
|
|
|
mount_uploader :header_logo, AttachmentUploader
|
2017-06-08 11:16:27 -04:00
|
|
|
has_many :uploads, as: :model, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
2017-08-09 10:41:51 -04:00
|
|
|
|
|
|
|
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-02-22 14:49:16 -05:00
|
|
|
end
|