mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 02:45:29 -04:00
Use is_valid?
This commit is contained in:
parent
872e6dc6d6
commit
e6dbeb623b
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user