Class: Scan::Model::AddNewFilesJob
- Inherits:
-
ApplicationJob
- Object
- ApplicationJob
- Scan::Model::AddNewFilesJob
- Defined in:
- app/jobs/scan/model/add_new_files_job.rb
Instance Method Summary collapse
- #file_list(model_path, library, include_all_subfolders: false) ⇒ Object
- #perform(model_id, include_all_subfolders: false) ⇒ Object
Instance Method Details
#file_list(model_path, library, include_all_subfolders: false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/jobs/scan/model/add_new_files_job.rb', line 7 def file_list(model_path, library, include_all_subfolders: false) glob = include_all_subfolders ? [File.join(Shellwords.escape(model_path), "**", FileMatcher.file_pattern)] : [File.join(Shellwords.escape(model_path), FileMatcher.file_pattern)] + FileMatcher.common_subfolders.map do |name, pattern| File.join( Shellwords.escape(model_path), FileMatcher.case_insensitive_glob_string(name), pattern ) end library.list_files(glob) + library.list_files(File.join(Shellwords.escape(model_path), "datapackage.json")) end |
#perform(model_id, include_all_subfolders: false) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/jobs/scan/model/add_new_files_job.rb', line 21 def perform(model_id, include_all_subfolders: false) model = Model.find(model_id) return if model.remote? return if Problem.create_or_clear(model, :missing, !model.exists_on_storage?) # For each file in the model, create a file object file_list(model.path, model.library, include_all_subfolders: include_all_subfolders).each do |filename| # Create the file file = model.model_files.find_or_create_by(filename: filename.gsub(model.path + "/", "")) file. if file.valid? && file.filename != "datapackage.json" end model. end |