mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 11:25:29 -04:00
Use macro to DRY the self.default
method
This commit is contained in:
parent
b75a838e14
commit
87b6e79952
@ -2,12 +2,7 @@ class Library
|
|||||||
property dir : String, title_ids : Array(String), scan_interval : Int32,
|
property dir : String, title_ids : Array(String), scan_interval : Int32,
|
||||||
title_hash : Hash(String, Title)
|
title_hash : Hash(String, Title)
|
||||||
|
|
||||||
def self.default : self
|
use_default
|
||||||
unless @@default
|
|
||||||
@@default = new
|
|
||||||
end
|
|
||||||
@@default.not_nil!
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
register_mime_types
|
register_mime_types
|
||||||
|
@ -8,12 +8,7 @@ class Logger
|
|||||||
|
|
||||||
@@severity : Log::Severity = :info
|
@@severity : Log::Severity = :info
|
||||||
|
|
||||||
def self.default : self
|
use_default
|
||||||
unless @@default
|
|
||||||
@@default = new
|
|
||||||
end
|
|
||||||
@@default.not_nil!
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
level = Config.current.log_level
|
level = Config.current.log_level
|
||||||
|
@ -131,12 +131,7 @@ module MangaDex
|
|||||||
end
|
end
|
||||||
|
|
||||||
class API
|
class API
|
||||||
def self.default : self
|
use_default
|
||||||
unless @@default
|
|
||||||
@@default = new
|
|
||||||
end
|
|
||||||
@@default.not_nil!
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@base_url = Config.current.mangadex["api_url"].to_s ||
|
@base_url = Config.current.mangadex["api_url"].to_s ||
|
||||||
|
@ -7,12 +7,7 @@ module MangaDex
|
|||||||
.to_i32
|
.to_i32
|
||||||
@retries : Int32 = Config.current.mangadex["download_retries"].to_i32
|
@retries : Int32 = Config.current.mangadex["download_retries"].to_i32
|
||||||
|
|
||||||
def self.default : self
|
use_default
|
||||||
unless @@default
|
|
||||||
@@default = new
|
|
||||||
end
|
|
||||||
@@default.not_nil!
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
class Plugin
|
class Plugin
|
||||||
class Downloader < Queue::Downloader
|
class Downloader < Queue::Downloader
|
||||||
|
use_default
|
||||||
def self.default : self
|
|
||||||
unless @@default
|
|
||||||
@@default = new
|
|
||||||
end
|
|
||||||
@@default.not_nil!
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
|
@ -92,12 +92,7 @@ class Queue
|
|||||||
@downloaders = [] of Downloader
|
@downloaders = [] of Downloader
|
||||||
@paused = false
|
@paused = false
|
||||||
|
|
||||||
def self.default : self
|
use_default
|
||||||
unless @@default
|
|
||||||
@@default = new
|
|
||||||
end
|
|
||||||
@@default.not_nil!
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize(db_path : String? = nil)
|
def initialize(db_path : String? = nil)
|
||||||
@path = db_path || Config.current.mangadex["download_queue_db_path"].to_s
|
@path = db_path || Config.current.mangadex["download_queue_db_path"].to_s
|
||||||
|
@ -10,12 +10,7 @@ class Context
|
|||||||
property storage : Storage
|
property storage : Storage
|
||||||
property queue : Queue
|
property queue : Queue
|
||||||
|
|
||||||
def self.default : self
|
use_default
|
||||||
unless @@default
|
|
||||||
@@default = new
|
|
||||||
end
|
|
||||||
@@default.not_nil!
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@storage = Storage.default
|
@storage = Storage.default
|
||||||
|
@ -21,12 +21,7 @@ class Storage
|
|||||||
id: String,
|
id: String,
|
||||||
is_title: Bool)
|
is_title: Bool)
|
||||||
|
|
||||||
def self.default : self
|
use_default
|
||||||
unless @@default
|
|
||||||
@@default = new
|
|
||||||
end
|
|
||||||
@@default.not_nil!
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize(db_path : String? = nil, init_user = true, *,
|
def initialize(db_path : String? = nil, init_user = true, *,
|
||||||
@auto_close = true)
|
@auto_close = true)
|
||||||
|
@ -45,3 +45,12 @@ struct Nil
|
|||||||
other
|
other
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
macro use_default
|
||||||
|
def self.default : self
|
||||||
|
unless @@default
|
||||||
|
@@default = new
|
||||||
|
end
|
||||||
|
@@default.not_nil!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user