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

#creator ⇒ Core::Models::Account

Returns the account of the person that uploaded the file.

Returns:



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

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

#folder ⇒ String

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.



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

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

#mime_type ⇒ String

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.



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

field :mime_type, type: String

#name ⇒ String

Returns the filename the user entered when uploading the file.

Returns:

  • (String) —

    the filename the user entered when uploading the file.



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

field :name, type: String

#permissions ⇒ Array<Core::Models::Files::Permission>

Returns the permissions granted to access this file.

Returns:



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

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

#size ⇒ String

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

Returns:

  • (String) —

    the size, in bytes, of the uploaded file.



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

field :size, type: Integer, default: 0

Instance Method Details

#filename_unicity ⇒ Object



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

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