diff --git a/src/library/archive_entry.cr b/src/library/archive_entry.cr index ab229af..da313cd 100644 --- a/src/library/archive_entry.cr +++ b/src/library/archive_entry.cr @@ -107,4 +107,8 @@ class ArchiveEntry < Entry def examine : Bool File.exists? @zip_path end + + def self.is_valid?(path : String) : Bool + is_supported_file path + end end diff --git a/src/library/dir_entry.cr b/src/library/dir_entry.cr index 59657af..82b7ccc 100644 --- a/src/library/dir_entry.cr +++ b/src/library/dir_entry.cr @@ -25,7 +25,7 @@ class DirEntry < Entry return end - unless DirEntry.validate_directory_entry @dir_path + unless DirEntry.is_valid? @dir_path @err_msg = "Directory #{@dir_path} is not valid directory entry." Logger.warn "#{@err_msg} Please make sure the " \ "directory has valid images." @@ -129,7 +129,7 @@ class DirEntry < Entry .sort { |a, b| compare_numerically a, b } end - def self.validate_directory_entry(dir_path) - image_files(dir_path).size > 0 + def self.is_valid?(path : String) : Bool + image_files(path).size > 0 end end diff --git a/src/library/entry.cr b/src/library/entry.cr index 5f19d77..131e489 100644 --- a/src/library/entry.cr +++ b/src/library/entry.cr @@ -28,8 +28,7 @@ abstract class Entry if err_msg json.field "err_msg", err_msg end - # for API backward compatability - json.field "zip_path", path + json.field "zip_path", path # for API backward compatability json.field "title_id", @book.id json.field "title_title", @book.title json.field "sort_title", sort_title @@ -220,6 +219,16 @@ abstract class Entry date_added.not_nil! # is it ok to set not_nil! here? end + # Hack to have abstract class methods + # https://github.com/crystal-lang/crystal/issues/5956 + private module ClassMethods + abstract def is_valid?(path : String) : Bool + end + + macro inherited + extend ClassMethods + end + abstract def path : String abstract def read_page(page_num) diff --git a/src/library/title.cr b/src/library/title.cr index 3f30490..e9873f2 100644 --- a/src/library/title.cr +++ b/src/library/title.cr @@ -53,7 +53,7 @@ class Title Library.default.title_hash[title.id] = title @title_ids << title.id end - if DirEntry.validate_directory_entry path + if DirEntry.is_valid? path entry = DirEntry.new path, self @entries << entry if entry.pages > 0 || entry.err_msg end @@ -146,7 +146,7 @@ class Title path = File.join dir, fn if File.directory? path unless remained_entry_paths.includes? path - if DirEntry.validate_directory_entry path + if DirEntry.is_valid? path entry = DirEntry.new path, self if entry.pages > 0 || entry.err_msg @entries << entry diff --git a/src/util/signature.cr b/src/util/signature.cr index 6f67a58..f0f68bd 100644 --- a/src/util/signature.cr +++ b/src/util/signature.cr @@ -64,7 +64,7 @@ class Dir path = File.join dirname, fn if File.directory? path signatures << Dir.contents_signature path, cache - if DirEntry.validate_directory_entry path + if DirEntry.is_valid? path signatures << fn end else