Much base work started
This commit is contained in:
27
app/models/storage_location.rb
Normal file
27
app/models/storage_location.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
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
|
||||
Reference in New Issue
Block a user