Class: Course::Material

Inherits:
ApplicationRecord show all
Includes:
DuplicationStateTrackingConcern
Defined in:
app/models/course/material.rb

Defined Under Namespace

Modules: FoldersHelper Classes: Controller, Folder, FoldersController, MaterialsController, PreloadService, ZipDownloadJob, ZipDownloadService

Instance Method Summary collapse

Methods included from DuplicationStateTrackingConcern

#clear_duplication_flag, #duplicating?, #set_duplication_flag

Instance Method Details

#before_duplicate_save(_duplicator) ⇒ Object


57
58
59
# File 'app/models/course/material.rb', line 57

def before_duplicate_save(_duplicator)
  self.name = next_valid_name
end

#initialize_duplicate(duplicator, other) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/course/material.rb', line 38

def initialize_duplicate(duplicator, other)
  self.attachment = duplicator.duplicate(other.attachment)
  self.folder = if duplicator.duplicated?(other.folder)
                  duplicator.duplicate(other.folder)
                else
                  # If parent has not been duplicated yet, put the current duplicate under the root folder
                  # temorarily. The material will be re-parented only afterwards when the parent folder is being
                  # duplicated. This will be done when `#initialize_duplicate_children` is called on the
                  # duplicated parent folder.
                  #
                  # If the material's folder is not selected for duplication, the current duplicated material will
                  # remain a child of the root folder.
                  duplicator.options[:destination_course].root_folder
                end
  self.updated_at = other.updated_at
  self.created_at = other.created_at
  set_duplication_flag
end

#next_valid_nameString

Finds a unique name for the current material among its siblings.


34
35
36
# File 'app/models/course/material.rb', line 34

def next_valid_name
  folder.next_uniq_child_name(self)
end

#pathPathname

Returns the path of the material


22
23
24
# File 'app/models/course/material.rb', line 22

def path
  folder.path + name
end

#record_userstampObject

Return false to prevent the userstamp gem from changing the updater during duplication


27
28
29
# File 'app/models/course/material.rb', line 27

def record_userstamp
  !duplicating?
end

#touch_folderObject


15
16
17
# File 'app/models/course/material.rb', line 15

def touch_folder
  folder.touch if !duplicating? && changed?
end