Class: Core::Models::Files::Document

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/core/models/files/document.rb

Overview

a document is an uploaded file in the S3 clone application.

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#creatorCore::Models::Account

Returns the account of the person that uploaded the file.

Returns:



30
# File 'lib/core/models/files/document.rb', line 30

belongs_to :creator, class_name: 'Core::Models::Account', inverse_of: :files

#folderString

Returns the folder in which the file is stored in the S3 clone.

Returns:

  • (String)

    the folder in which the file is stored in the S3 clone.



22
# File 'lib/core/models/files/document.rb', line 22

field :folder, type: String, default: '/'

#mime_typeString

Returns the MIME type of the file. this MAY not correspond to the real MIME type of the uploaded file, this is just an indication.

Returns:

  • (String)

    the MIME type of the file. this MAY not correspond to the real MIME type of the uploaded file, this is just an indication.



26
# File 'lib/core/models/files/document.rb', line 26

field :mime_type, type: String

#nameString

Returns the filename the user entered when uploading the file.

Returns:

  • (String)

    the filename the user entered when uploading the file.



14
# File 'lib/core/models/files/document.rb', line 14

field :name, type: String

#permissionsArray<Core::Models::Files::Permission>

Returns the permissions granted to access this file.

Returns:



34
# File 'lib/core/models/files/document.rb', line 34

has_many :permissions, class_name: 'Core::Models::Files::Permission', inverse_of: :file

#sizeString

Returns the size, in bytes, of the uploaded file.

Returns:

  • (String)

    the size, in bytes, of the uploaded file.



19
# File 'lib/core/models/files/document.rb', line 19

field :size, type: Integer, default: 0

Instance Method Details

#filename_unicityObject



42
43
44
45
46
47
48
49
50
# File 'lib/core/models/files/document.rb', line 42

def filename_unicity
  existing = Core::Models::Files::Document.where(
    name: name,
    folder: folder,
    extension: extension,
    :id.ne => id
  )
  errors.add(:name, 'uniq') unless existing.first.nil?
end