-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from hhru/type-decoding
Исправлен декодинг типов токенов
- Loading branch information
Showing
9 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Foundation | ||
|
||
struct DefaultLoggerPrinter: LoggerPrinting { | ||
|
||
// MARK: - LoggerPrinting | ||
|
||
func print(_ message: String, terminator: String) { | ||
Swift.print(message, terminator: terminator) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import Foundation | ||
|
||
struct Logger { | ||
|
||
// MARK: - Type Properties | ||
|
||
static let verboseLogKey = "VERBOSE_LOG" | ||
|
||
// MARK: - Instance Properties | ||
|
||
let isSilent: Bool | ||
let printer: LoggerPrinting | ||
|
||
var isVerbose: Bool { | ||
ProcessInfo.processInfo.environment[Self.verboseLogKey] != nil | ||
} | ||
|
||
// MARK: - Initializers | ||
|
||
init(isSilent: Bool = false, printer: LoggerPrinting = DefaultLoggerPrinter()) { | ||
self.isSilent = isSilent | ||
self.printer = printer | ||
} | ||
|
||
// MARK: - Instance Methods | ||
|
||
private func print(_ message: String, terminator: String = "\n", isVerbose: Bool) { | ||
guard !isSilent else { | ||
return | ||
} | ||
|
||
guard !isVerbose || (isVerbose && self.isVerbose) else { | ||
return | ||
} | ||
|
||
printer.print(message, terminator: terminator) | ||
} | ||
|
||
// MARK: - | ||
|
||
func debug(_ items: Any..., separator: String = " ", terminator: String = "\n", isVerbose: Bool = true) { | ||
let message = items.joinedDescription(separator: separator) | ||
print(message, terminator: terminator, isVerbose: isVerbose) | ||
} | ||
|
||
func info(_ items: Any..., separator: String = " ", terminator: String = "\n", isVerbose: Bool = false) { | ||
let message = items.joinedDescription(separator: separator) | ||
print(message, terminator: terminator, isVerbose: isVerbose) | ||
} | ||
|
||
func warning(_ items: Any..., separator: String = " ", terminator: String = "\n", isVerbose: Bool = false) { | ||
let message = "⚠️ WARNING: \(items.joinedDescription(separator: separator))".yellow | ||
print(message, terminator: terminator, isVerbose: isVerbose) | ||
} | ||
|
||
func success(_ items: Any..., separator: String = " ", terminator: String = "\n", isVerbose: Bool = false) { | ||
let message = "✅ \(items.joinedDescription(separator: separator))".green | ||
print(message, terminator: terminator, isVerbose: isVerbose) | ||
} | ||
|
||
func error(_ items: Any..., separator: String = " ", terminator: String = "\n", isVerbose: Bool = false) { | ||
let message = "🛑 ERROR: \(items.joinedDescription(separator: separator))".red | ||
print(message, terminator: terminator, isVerbose: isVerbose) | ||
} | ||
} | ||
|
||
// MARK: - | ||
|
||
extension Sequence { | ||
|
||
// MARK: - Instance Methods | ||
|
||
fileprivate func joinedDescription(separator: String) -> String { | ||
map { "\($0)" }.joined(separator: separator) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Foundation | ||
|
||
protocol LoggerPrinting { | ||
|
||
// MARK: - Instance Methods | ||
|
||
func print(_ message: String, terminator: String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters