def each
      SemanticLogger.named_tagged(dirmon_entry: id.to_s) do
        # Case insensitive filename matching
        Pathname.glob(pattern, File::FNM_CASEFOLD).each do |pathname|
          next if pathname.directory?
          pathname = begin
            pathname.realpath
          rescue Errno::ENOENT
            logger.warn("Unable to expand the realpath for #{pathname.inspect}. Skipping file.")
            next
          end

          file_name = pathname.to_s

          # Skip archive directories
          next if file_name.include?(self.class.default_archive_directory)

          # Security check?
          if whitelist_paths.size.positive? && whitelist_paths.none? { |whitepath| file_name.to_s.start_with?(whitepath) }
            logger.error "Skipping file: #{file_name} since it is not in any of the whitelisted paths: #{whitelist_paths.join(', ')}"
            next
          end

          # File must be writable so it can be removed after processing
          unless pathname.writable?
            logger.error "Skipping file: #{file_name} since it is not writable by the current user. Must be able to delete/move the file after queueing the job"
            next
          end
          yield(pathname)
        end
      end
    end
def each
      SemanticLogger.named_tagged(dirmon_entry: id.to_s) do
        # Case insensitive filename matching
        Pathname.glob(pattern, File::FNM_CASEFOLD).each do |pathname|
          next if pathname.directory?
          pathname = begin
            pathname.realpath
          rescue Errno::ENOENT
            logger.warn("Unable to expand the realpath for #{pathname.inspect}. Skipping file.")
            next
          end

          file_name = pathname.to_s

          # Skip archive directories
          next if file_name.include?(self.class.default_archive_directory)

          # Security check?
          if whitelist_paths.size.positive? && whitelist_paths.none? { |whitepath| file_name.to_s.start_with?(whitepath) }
            logger.error "Skipping file: #{file_name} since it is not in any of the whitelisted paths: #{whitelist_paths.join(', ')}"
            next
          end

          # File must be writable so it can be removed after processing
          unless pathname.writable?
            logger.error "Skipping file: #{file_name} since it is not writable by the current user. Must be able to delete/move the file after queueing the job"
            next
          end
          yield(pathname)
        end
      end
    end
Passes each filename [Pathname] found that matches the pattern into the supplied block