Class: Nexo::FolderService
- Inherits:
-
Object
- Object
- Nexo::FolderService
- Defined in:
- app/lib/nexo/folder_service.rb
Overview
Handles the composition of folders
Responsabilities:
-
Creation of Element’s
-
Creation of ElementVersion on local changes
-
Flagging Element’s for removal
-
Enqueues UpdateRemoteResourceJob, DeleteRemoteResourceJob
Instance Method Summary collapse
- #destroy_elements(synchronizable, reason, exclude_elements: []) ⇒ Object
- #find_element_and_sync(folder, synchronizable) ⇒ Object
Instance Method Details
#destroy_elements(synchronizable, reason, exclude_elements: []) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/lib/nexo/folder_service.rb', line 26 def destroy_elements(synchronizable, reason, exclude_elements: []) Nexo.logger.debug("Destroying elements for synchronizable") scope = synchronizable.nexo_elements if exclude_elements.any? Nexo.logger.debug("Excluding elements: #{exclude_elements}") scope = scope.where.not(id: exclude_elements) end scope.each do |element| unless element.folder.sync_internal_changes? Nexo.logger.debug("Folder dont syncs internal changes, skipping") next end ElementService.new(element:).flag_for_removal!(reason) DeleteRemoteResourceJob.perform_later(element) end end |
#find_element_and_sync(folder, synchronizable) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/lib/nexo/folder_service.rb', line 11 def find_element_and_sync(folder, synchronizable) validate_synchronizable!(synchronizable) element = folder.find_element(synchronizable:) if element.present? Nexo.logger.debug { "Element found" } validate_element_state!(element) sync_element(element) else Nexo.logger.debug { "Element not found" } create_and_sync_element(folder, synchronizable) end end |