2019-01-13 07:05:54 +01:00
|
|
|
class Document < ApplicationRecord
|
2017-11-08 22:35:12 +01:00
|
|
|
include ActsAsTree
|
2016-04-28 13:46:13 +02:00
|
|
|
|
2017-11-08 22:35:12 +01:00
|
|
|
belongs_to :created_by, class_name: 'User', foreign_key: 'created_by_user_id'
|
|
|
|
|
|
|
|
acts_as_tree
|
|
|
|
|
|
|
|
def file?
|
|
|
|
!folder?
|
|
|
|
end
|
|
|
|
|
|
|
|
def folder?
|
|
|
|
mime.nil?
|
|
|
|
end
|
2017-10-11 01:30:29 +02:00
|
|
|
|
|
|
|
def filename
|
|
|
|
types = MIME::Types[mime]
|
|
|
|
|
|
|
|
if name.include? '.'
|
|
|
|
types.each do |type|
|
|
|
|
type.extensions.each do |extension|
|
|
|
|
return name if name.end_with? ".#{extension}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
"#{name}.#{types.first.preferred_extension}"
|
|
|
|
end
|
|
|
|
|
2016-04-28 13:46:13 +02:00
|
|
|
end
|