28 lines
565 B
Ruby
28 lines
565 B
Ruby
class StorageLocation < ApplicationRecord
|
|
has_many :videos, dependent: :destroy
|
|
|
|
validates :name, presence: true
|
|
validates :path, presence: true, uniqueness: true
|
|
validates :storage_type, presence: true, inclusion: { in: %w[local] }
|
|
|
|
validate :path_must_exist_and_be_readable
|
|
|
|
def accessible?
|
|
File.exist?(path) && File.readable?(path)
|
|
end
|
|
|
|
def video_count
|
|
videos.count
|
|
end
|
|
|
|
def display_name
|
|
name
|
|
end
|
|
|
|
private
|
|
|
|
def path_must_exist_and_be_readable
|
|
errors.add(:path, "must exist and be readable") unless accessible?
|
|
end
|
|
end
|