Skip to content

Commit

Permalink
Rename package to SwiftSpellbook
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkenso committed Oct 18, 2023
1 parent 54ce340 commit 17a57c7
Show file tree
Hide file tree
Showing 114 changed files with 165 additions and 161 deletions.
30 changes: 15 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,51 @@
import PackageDescription

let package = Package(
name: "SwiftConvenience",
name: "SwiftSpellbook",
platforms: [.macOS(.v10_10), .iOS(.v9), .tvOS(.v9), .watchOS(.v2)],
products: [
.library(
name: "SwiftConvenience",
targets: ["SwiftConvenience"]
name: "SpellbookFoundation",
targets: ["SpellbookFoundation"]
),
.library(
name: "SpellbookHTTP",
targets: ["SpellbookHTTP"]
),
.library(
name: "SwiftConvenienceTestUtils",
targets: ["SwiftConvenienceTestUtils"]
name: "SpellbookTestUtils",
targets: ["SpellbookTestUtils"]
),
],
dependencies: [
],
targets: [
.target(
name: "SwiftConvenience",
dependencies: ["SwiftConvenienceObjC"],
name: "SpellbookFoundation",
dependencies: ["SpellbookFoundationObjC"],
linkerSettings: [
.linkedLibrary("bsm", .when(platforms: [.macOS])),
]
),
.target(
name: "SwiftConvenienceObjC",
name: "SpellbookFoundationObjC",
publicHeadersPath: "."
),
.target(
name: "SpellbookHTTP",
dependencies: ["SwiftConvenience"]
dependencies: ["SpellbookFoundation"]
),
.target(
name: "SwiftConvenienceTestUtils",
dependencies: ["SwiftConvenience"]
name: "SpellbookTestUtils",
dependencies: ["SpellbookFoundation"]
),
.testTarget(
name: "SwiftConvenienceTests",
dependencies: ["SwiftConvenience", "SwiftConvenienceTestUtils"]
name: "SpellbookTests",
dependencies: ["SpellbookFoundation", "SpellbookTestUtils"]
),
.testTarget(
name: "SwiftConvenienceTestUtilsTests",
dependencies: ["SwiftConvenience", "SwiftConvenienceTestUtils"]
name: "SpellbookTestUtilsTests",
dependencies: ["SpellbookFoundation", "SpellbookTestUtils"]
),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

import Foundation

private let codableLogger = SCLogger.internal(category: "Codable")
private let codableLogger = SpellbookLogger.internal(category: "Codable")

extension Encodable {
/// Encode value to json using specified encoder.
/// Log failure to SwiftConvenience.Log
/// Log failure to SpellbookLog.
public func encode(
with encoder: ObjectEncoder<Self>,
file: StaticString = #file, _ function: StaticString = #function, line: Int = #line, log: SCLog? = nil
file: StaticString = #file, _ function: StaticString = #function, line: Int = #line, log: SpellbookLog? = nil
) -> Data? {
do {
return try encoder.encode(self)
Expand Down Expand Up @@ -84,10 +84,10 @@ extension ObjectEncoder {

extension Decodable {
/// Initialize value from json using specified decoder.
/// Log failure to SwiftConvenience.Log
/// Log failure to SpellbookLog.
public init?(
from data: Data, decoder: ObjectDecoder<Self>,
file: StaticString = #file, _ function: StaticString = #function, line: Int = #line, log: SCLog? = nil
file: StaticString = #file, _ function: StaticString = #function, line: Int = #line, log: SpellbookLog? = nil
) {
do {
self = try decoder.decode(Self.self, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import Foundation

/// Custom Error key which value is object related to the failure.
public let SCRelatedObjectErrorKey: String = "SCRelatedObjectErrorKey"
public let SBRelatedObjectErrorKey: String = "SBRelatedObjectErrorKey"

/// Custom Error key which value is name of some entity the error is about.
public let SCNameErrorKey: String = "SCNameErrorKey"
public let SBNameErrorKey: String = "SBNameErrorKey"

// MARK: - NSError predefined domains

Expand Down Expand Up @@ -138,7 +138,7 @@ extension NSError.TryBuilder {
}

public func named(_ name: String) -> Self {
userInfo(name, for: SCNameErrorKey)
userInfo(name, for: SBNameErrorKey)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

import Foundation

public protocol SCUnit: RawRepresentable where RawValue == Double {}
public protocol SBUnit: RawRepresentable where RawValue == Double {}

extension SCUnit {
extension SBUnit {
// public static func convert(_ value: Double, to: Self) -> Double { value / to.rawValue }
// public static func restore(_ magnitude: Double, of: Self) -> Double { magnitude * of.rawValue }
/// Perform conversion between measurement units.
Expand All @@ -37,7 +37,7 @@ extension SCUnit {
}
}

public struct SCUnitInformationStorage: SCUnit {
public struct SBUnitInformationStorage: SBUnit {
public var rawValue: Double
public init(rawValue: Double) { self.rawValue = rawValue }

Expand All @@ -46,7 +46,7 @@ public struct SCUnitInformationStorage: SCUnit {
public static let gigabyte = Self(rawValue: 1024 * megabyte.rawValue)
}

public struct SCUnitTime: SCUnit {
public struct SBUnitTime: SBUnit {
public var rawValue: Double
public init(rawValue: Double) { self.rawValue = rawValue }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

import Foundation

public protocol SCLog {
func custom(level: SCLogLevel, message: @autoclosure () -> Any, assert: Bool, file: StaticString, function: StaticString, line: Int)
public protocol SpellbookLog {
func custom(level: SpellbookLogLevel, message: @autoclosure () -> Any, assert: Bool, file: StaticString, function: StaticString, line: Int)
}

extension SCLog {
extension SpellbookLog {
public func verbose(_ message: @autoclosure () -> Any, _ file: StaticString = #file, _ function: StaticString = #function, line: Int = #line) {
custom(level: .verbose, message: message(), assert: false, file, function, line)
}
Expand All @@ -52,14 +52,14 @@ extension SCLog {
}

public func custom(
level: SCLogLevel, message: @autoclosure () -> Any, assert: Bool,
level: SpellbookLogLevel, message: @autoclosure () -> Any, assert: Bool,
_ file: StaticString = #file, _ function: StaticString = #function, _ line: Int = #line
) {
custom(level: level, message: message(), assert: assert, file: file, function: function, line: line)
}
}

public enum SCLogLevel: Int, Hashable {
public enum SpellbookLogLevel: Int, Hashable {
case verbose = 0 /// something generally unimportant.
case debug = 1 /// something which help during debugging.
case info = 2 /// something which you are really interested but which is not an issue or error.
Expand All @@ -68,21 +68,21 @@ public enum SCLogLevel: Int, Hashable {
case fatal = 5 /// something which will keep you awake at night.
}

extension SCLogLevel: Comparable {
public static func < (lhs: SCLogLevel, rhs: SCLogLevel) -> Bool {
extension SpellbookLogLevel: Comparable {
public static func < (lhs: SpellbookLogLevel, rhs: SpellbookLogLevel) -> Bool {
lhs.rawValue < rhs.rawValue
}
}

public struct SCLogRecord {
public var source: SCLogSource
public var level: SCLogLevel
public struct SpellbookLogRecord {
public var source: SpellbookLogSource
public var level: SpellbookLogLevel
public var message: Any
public var file: StaticString
public var function: StaticString
public var line: Int

public init(source: SCLogSource, level: SCLogLevel, message: Any, file: StaticString, function: StaticString, line: Int) {
public init(source: SpellbookLogSource, level: SpellbookLogLevel, message: Any, file: StaticString, function: StaticString, line: Int) {
self.source = source
self.level = level
self.message = message
Expand All @@ -92,7 +92,7 @@ public struct SCLogRecord {
}
}

public struct SCLogSource {
public struct SpellbookLogSource {
public var subsystem: String
public var category: String
public var context: Any?
Expand All @@ -104,48 +104,48 @@ public struct SCLogSource {
}
}

extension SCLogSource {
extension SpellbookLogSource {
public static func `default`(category: String = "Generic") -> Self {
SCLogSource(
SpellbookLogSource(
subsystem: Bundle.main.bundleIdentifier ?? "Generic",
category: category
)
}
}

extension SCLogSource: CustomStringConvertible {
extension SpellbookLogSource: CustomStringConvertible {
public var description: String { "\(subsystem)/\(category)" }
}

public final class SCLogger {
private let queue: DispatchQueue
public final class SpellbookLogger {
private let queue: DispatchQueue?

public init(name: String) {
queue = DispatchQueue(label: "SwiftConvenienceLog.\(name).queue")
public init(name: String, useQueue: Bool = true) {
queue = useQueue ? DispatchQueue(label: "SpellbookLog.\(name).queue") : nil
}

public static let `default` = SCLogger(name: "default")
public static var `default` = SpellbookLogger(name: "default")

public var source = SCLogSource.default()
public var source = SpellbookLogSource.default()

public var destinations: [(SCLogRecord) -> Void] = []
public var destinations: [(SpellbookLogRecord) -> Void] = []

public var minLevel: SCLogLevel = .info
public var minLevel: SpellbookLogLevel = .info

/// If log messages with `assert = true` should really produce asserts.
public var isAssertsEnabled = true

/// Create child instance, replacing log source.
/// Children perform log facilities through their parent.
public func withSource(_ source: SCLogSource) -> SCLog {
SCSubsystemLogger {
public func withSource(_ source: SpellbookLogSource) -> SpellbookLog {
SubsystemLogger {
self.custom(source: source, level: $0, message: $1(), assert: $2, file: $3, function: $4, line: $5)
}
}

/// Create child instance, replacing log subsystem.
/// Children perform log facilities through their parent.
public func with(subsystem: String? = nil, category: String) -> SCLog {
public func with(subsystem: String? = nil, category: String) -> SpellbookLog {
var source = source
subsystem.flatMap { source.subsystem = $0 }
source.category = category
Expand All @@ -154,22 +154,22 @@ public final class SCLogger {
}
}

extension SCLogger {
extension SpellbookLogger {
/// Subsystem name used by default.
public static var internalSubsystem = "SwiftConvenience"
public static var internalSubsystem = "Spellbook"

internal static func `internal`(category: String) -> SCLog {
internal static func `internal`(category: String) -> SpellbookLog {
`default`.with(subsystem: internalSubsystem, category: category)
}
}

extension SCLogger: SCLog {
public func custom(level: SCLogLevel, message: @autoclosure () -> Any, assert: Bool, file: StaticString, function: StaticString, line: Int) {
extension SpellbookLogger: SpellbookLog {
public func custom(level: SpellbookLogLevel, message: @autoclosure () -> Any, assert: Bool, file: StaticString, function: StaticString, line: Int) {
custom(source: source, level: level, message: message(), assert: assert, file: file, function: function, line: line)
}

private func custom(
source: SCLogSource, level: SCLogLevel, message: @autoclosure () -> Any, assert: Bool,
source: SpellbookLogSource, level: SpellbookLogLevel, message: @autoclosure () -> Any, assert: Bool,
file: StaticString, function: StaticString, line: Int
) {
guard level >= minLevel else { return }
Expand All @@ -178,20 +178,24 @@ extension SCLogger: SCLog {
assertionFailure("\(message())", file: file, line: UInt(line))
}

let record = SCLogRecord(
let record = SpellbookLogRecord(
source: source, level: level, message: message(),
file: file, function: function, line: line
)
queue.async {
if let queue {
queue.async {
self.destinations.forEach { $0(record) }
}
} else {
self.destinations.forEach { $0(record) }
}
}
}

private struct SCSubsystemLogger: SCLog {
let logImpl: (_ level: SCLogLevel, _ message: @autoclosure () -> Any, _ assert: Bool, _ file: StaticString, _ function: StaticString, _ line: Int) -> Void
private struct SubsystemLogger: SpellbookLog {
let logImpl: (_ level: SpellbookLogLevel, _ message: @autoclosure () -> Any, _ assert: Bool, _ file: StaticString, _ function: StaticString, _ line: Int) -> Void

func custom(level: SCLogLevel, message: @autoclosure () -> Any, assert: Bool, file: StaticString, function: StaticString, line: Int) {
func custom(level: SpellbookLogLevel, message: @autoclosure () -> Any, assert: Bool, file: StaticString, function: StaticString, line: Int) {
logImpl(level, message(), assert, file, function, line)
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ extension DictionaryCodingError: CustomNSError {
userInfo[NSDebugDescriptionErrorKey] = fullDescription

underlyingError.flatMap { userInfo[NSUnderlyingErrorKey] = $0 }
relatedObject.flatMap { userInfo[SCRelatedObjectErrorKey] = $0 }
relatedObject.flatMap { userInfo[SBRelatedObjectErrorKey] = $0 }

return userInfo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#if os(macOS)

import Foundation
@_implementationOnly import SwiftConvenienceObjC
@_implementationOnly import SpellbookFoundationObjC

extension audit_token_t {
/// Returns current task audit token.
Expand Down Expand Up @@ -66,7 +66,7 @@ extension audit_token_t: SafePOD, UnsafePOD {}

extension NSXPCConnection {
public var auditToken: audit_token_t {
SwiftConvenienceObjC.nsxpcConnection_auditToken(self)
SpellbookObjC.nsxpcConnection_auditToken(self)
}
}

Expand Down
Loading

0 comments on commit 17a57c7

Please sign in to comment.