Class: ProjectFileInventory
- Inherits:
-
Object
- Object
- ProjectFileInventory
- Defined in:
- app/models/project_file_inventory.rb
Instance Method Summary collapse
-
#generate ⇒ Object
Generate the file with the file inventory.
-
#initialize(project:, session_id:, filename:) ⇒ ProjectFileInventory
constructor
A new instance of ProjectFileInventory.
Constructor Details
#initialize(project:, session_id:, filename:) ⇒ ProjectFileInventory
Returns a new instance of ProjectFileInventory.
3 4 5 6 7 8 9 10 |
# File 'app/models/project_file_inventory.rb', line 3 def initialize(project:, session_id:, filename:) @project = project @session_id = session_id @filename = filename @paths_queue = [] @log_prefix = "file_list_to_file #{session_id[0..7]} #{project.mediaflux_id}" @io_file = nil end |
Instance Method Details
#generate ⇒ Object
Generate the file with the file inventory
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/project_file_inventory.rb', line 13 def generate() start_time = Time.zone.now log_elapsed(start_time, "STARTED") @io_file = File.open(@filename, "a") @io_file.write("ID, PATH, NAME, COLLECTION?, LAST_MODIFIED, SIZE\r\n") # Add the root of the project to the queue... add_path_to_queue(collection_id: @project.mediaflux_id, path_prefix: @project.project_directory) # ... and start processing (more paths might be added during `process_path`) loop do next_path = @paths_queue.pop() break if next_path.nil? process_path(collection_id: next_path[:collection_id], path_prefix: next_path[:path_prefix]) end ensure @io_file.close log_elapsed(start_time, "ENDED") end |