mirror of
https://github.com/manyfold3d/manyfold.git
synced 2026-10-21 19:22:18 -05:00
Move file glob methods into their own module
This commit is contained in:
5 files changed
+50
-49
No files matched your search
@@ -26,46 +26,4 @@ class ApplicationJob < ActiveJob::Base
|
||||
step: nil
|
||||
)
|
||||
end
|
||||
|
||||
def self.extension_glob(extensions)
|
||||
[
|
||||
"*.{",
|
||||
extensions.map { |ext| case_insensitive_glob_string(ext) }.join(","),
|
||||
"}"
|
||||
].join
|
||||
end
|
||||
|
||||
def self.case_insensitive_glob_string(str)
|
||||
str.chars.map { |char|
|
||||
"[#{char.upcase}#{char.downcase}]"
|
||||
}.join
|
||||
end
|
||||
|
||||
def self.image_pattern
|
||||
extension_glob(SupportedMimeTypes.image_extensions)
|
||||
end
|
||||
|
||||
def self.file_pattern
|
||||
extension_glob(SupportedMimeTypes.indexable_extensions)
|
||||
end
|
||||
|
||||
def self.common_subfolders
|
||||
{
|
||||
"3mf" => file_pattern,
|
||||
"fdm" => file_pattern,
|
||||
"files" => file_pattern,
|
||||
"images" => image_pattern,
|
||||
"lychee" => file_pattern,
|
||||
"lys" => file_pattern,
|
||||
"model" => file_pattern,
|
||||
"obj" => file_pattern,
|
||||
"parts" => file_pattern,
|
||||
"presupported" => file_pattern,
|
||||
"resin" => file_pattern,
|
||||
"stl" => file_pattern,
|
||||
"sup" => file_pattern,
|
||||
"supported" => file_pattern,
|
||||
"unsupported" => file_pattern
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -4,7 +4,7 @@ class Scan::Library::DetectFilesystemChangesJob < ApplicationJob
|
||||
|
||||
# Find all files in the library that we might need to look at
|
||||
def filenames_on_disk(library)
|
||||
library.list_files(File.join("**", ApplicationJob.file_pattern))
|
||||
library.list_files(File.join("**", FileMatcher.file_pattern))
|
||||
end
|
||||
|
||||
# Get a list of all the existing filenames
|
||||
@@ -13,7 +13,7 @@ class Scan::Library::DetectFilesystemChangesJob < ApplicationJob
|
||||
end
|
||||
|
||||
def filter_out_common_subfolders(folders)
|
||||
matcher = /\/(#{ApplicationJob.common_subfolders.keys.join("|")})$/i
|
||||
matcher = /\/(#{FileMatcher.common_subfolders.keys.join("|")})$/i
|
||||
folders.map { |f| f.gsub(matcher, "") }.uniq
|
||||
end
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@ class Scan::Model::AddNewFilesJob < ApplicationJob
|
||||
|
||||
def file_list(model_path, library, include_all_subfolders: false)
|
||||
glob = include_all_subfolders ?
|
||||
[File.join(Shellwords.escape(model_path), "**", ApplicationJob.file_pattern)] :
|
||||
[File.join(Shellwords.escape(model_path), ApplicationJob.file_pattern)] +
|
||||
ApplicationJob.common_subfolders.map do |name, pattern|
|
||||
[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),
|
||||
ApplicationJob.case_insensitive_glob_string(name),
|
||||
FileMatcher.case_insensitive_glob_string(name),
|
||||
pattern
|
||||
)
|
||||
end
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
module FileMatcher
|
||||
def self.extension_glob(extensions)
|
||||
[
|
||||
"*.{",
|
||||
extensions.map { |ext| case_insensitive_glob_string(ext) }.join(","),
|
||||
"}"
|
||||
].join
|
||||
end
|
||||
|
||||
def self.case_insensitive_glob_string(str)
|
||||
str.chars.map { |char|
|
||||
"[#{char.upcase}#{char.downcase}]"
|
||||
}.join
|
||||
end
|
||||
|
||||
def self.image_pattern
|
||||
extension_glob(SupportedMimeTypes.image_extensions)
|
||||
end
|
||||
|
||||
def self.file_pattern
|
||||
extension_glob(SupportedMimeTypes.indexable_extensions)
|
||||
end
|
||||
|
||||
def self.common_subfolders
|
||||
{
|
||||
"3mf" => file_pattern,
|
||||
"fdm" => file_pattern,
|
||||
"files" => file_pattern,
|
||||
"images" => image_pattern,
|
||||
"lychee" => file_pattern,
|
||||
"lys" => file_pattern,
|
||||
"model" => file_pattern,
|
||||
"obj" => file_pattern,
|
||||
"parts" => file_pattern,
|
||||
"presupported" => file_pattern,
|
||||
"resin" => file_pattern,
|
||||
"stl" => file_pattern,
|
||||
"sup" => file_pattern,
|
||||
"supported" => file_pattern,
|
||||
"unsupported" => file_pattern
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe ApplicationJob do
|
||||
RSpec.describe FileMatcher do
|
||||
it "generates a case-insensitive pattern for all supported files" do # rubocop:todo RSpec/MultipleExpectations
|
||||
pattern = described_class.file_pattern
|
||||
expect(pattern).to include "[Ss][Tt][Ll],"
|
||||
Reference in new issue
Block a user