Class: Arkaan::Files::Document

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/arkaan/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

#creatorArkaan::Account

Returns the account of the person that uploaded the file.

Returns:



29
# File 'lib/arkaan/files/document.rb', line 29

belongs_to :creator, class_name: 'Arkaan::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.



21
# File 'lib/arkaan/files/document.rb', line 21

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.



25
# File 'lib/arkaan/files/document.rb', line 25

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.



13
# File 'lib/arkaan/files/document.rb', line 13

field :name, type: String

#permissionsArray<Arkaan::Files::Permission>

Returns the permissions granted to access this file.

Returns:



33
# File 'lib/arkaan/files/document.rb', line 33

has_many :permissions, class_name: 'Arkaan::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.



18
# File 'lib/arkaan/files/document.rb', line 18

field :size, type: Integer, default: 0

Instance Method Details

#filename_unicityObject



41
42
43
44
45
46
47
48
49
# File 'lib/arkaan/files/document.rb', line 41

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