mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-21 17:09:42 +01:00
WIP: logging clauses
This commit is contained in:
@@ -87,7 +87,7 @@ public struct From<T: NSManagedObject> {
|
||||
- parameter configuration: the `NSPersistentStore` configuration name to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration.
|
||||
- parameter otherConfigurations: an optional list of other configuration names to associate objects from (see `configuration` parameter)
|
||||
*/
|
||||
public init(_ configuration: String?, otherConfigurations: String?...) {
|
||||
public init(_ configuration: String?, _ otherConfigurations: String?...) {
|
||||
|
||||
self.init(entityClass: T.self, configurations: [configuration] + otherConfigurations)
|
||||
}
|
||||
@@ -300,6 +300,9 @@ public struct From<T: NSManagedObject> {
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
internal let entityClass: AnyClass
|
||||
internal let dumpInfo: (key: String, value: Any)?
|
||||
|
||||
internal func applyToFetchRequest(fetchRequest: NSFetchRequest, context: NSManagedObjectContext, applyAffectedStores: Bool = true) {
|
||||
|
||||
fetchRequest.entity = context.entityDescriptionForEntityClass(self.entityClass)
|
||||
@@ -320,6 +323,7 @@ public struct From<T: NSManagedObject> {
|
||||
|
||||
return From<NSManagedObject>(
|
||||
entityClass: self.entityClass,
|
||||
dumpInfo: self.dumpInfo,
|
||||
findPersistentStores: self.findPersistentStores
|
||||
)
|
||||
}
|
||||
@@ -327,13 +331,13 @@ public struct From<T: NSManagedObject> {
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let entityClass: AnyClass
|
||||
private let findPersistentStores: (context: NSManagedObjectContext) -> [NSPersistentStore]?
|
||||
|
||||
private init(entityClass: AnyClass) {
|
||||
|
||||
self.init(
|
||||
entityClass: entityClass,
|
||||
dumpInfo: nil,
|
||||
findPersistentStores: { (context: NSManagedObjectContext) -> [NSPersistentStore]? in
|
||||
|
||||
return context.parentStack?.persistentStoresForEntityClass(entityClass)
|
||||
@@ -346,6 +350,7 @@ public struct From<T: NSManagedObject> {
|
||||
let configurationsSet = Set(configurations.map { $0 ?? Into.defaultConfigurationName })
|
||||
self.init(
|
||||
entityClass: entityClass,
|
||||
dumpInfo: ("configurations", configurations),
|
||||
findPersistentStores: { (context: NSManagedObjectContext) -> [NSPersistentStore]? in
|
||||
|
||||
return context.parentStack?.persistentStoresForEntityClass(entityClass)?.filter {
|
||||
@@ -361,6 +366,7 @@ public struct From<T: NSManagedObject> {
|
||||
let storeURLsSet = Set(storeURLs)
|
||||
self.init(
|
||||
entityClass: entityClass,
|
||||
dumpInfo: ("storeURLs", storeURLs),
|
||||
findPersistentStores: { (context: NSManagedObjectContext) -> [NSPersistentStore]? in
|
||||
|
||||
return context.parentStack?.persistentStoresForEntityClass(entityClass)?.filter {
|
||||
@@ -376,6 +382,7 @@ public struct From<T: NSManagedObject> {
|
||||
let persistentStores = Set(persistentStores)
|
||||
self.init(
|
||||
entityClass: entityClass,
|
||||
dumpInfo: ("persistentStores", persistentStores),
|
||||
findPersistentStores: { (context: NSManagedObjectContext) -> [NSPersistentStore]? in
|
||||
|
||||
return context.parentStack?.persistentStoresForEntityClass(entityClass)?.filter {
|
||||
@@ -386,9 +393,10 @@ public struct From<T: NSManagedObject> {
|
||||
)
|
||||
}
|
||||
|
||||
private init(entityClass: AnyClass, findPersistentStores: (context: NSManagedObjectContext) -> [NSPersistentStore]?) {
|
||||
private init(entityClass: AnyClass, dumpInfo: (key: String, value: Any)?, findPersistentStores: (context: NSManagedObjectContext) -> [NSPersistentStore]?) {
|
||||
|
||||
self.entityClass = entityClass
|
||||
self.dumpInfo = dumpInfo
|
||||
self.findPersistentStores = findPersistentStores
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +87,11 @@ extension CloudStorageOptions: CustomDebugStringConvertible, IndentableDebugStri
|
||||
return "[.\(flags[0])]"
|
||||
|
||||
default:
|
||||
let description = "[\n" + flags.joinWithSeparator(",\n")
|
||||
return description.indent(1) + "\n]"
|
||||
var string = "[\n"
|
||||
string.appendContentsOf(flags.joinWithSeparator(",\n"))
|
||||
string.indent(1)
|
||||
string.appendContentsOf("\n")
|
||||
return string
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,6 +181,32 @@ extension DataStack: CustomDebugStringConvertible, IndentableDebugStringConverti
|
||||
}
|
||||
|
||||
|
||||
// MARK: - From
|
||||
|
||||
extension From: CustomDebugStringConvertible, IndentableDebugStringConvertible {
|
||||
|
||||
// MARK: CustomDebugStringConvertible
|
||||
|
||||
public var debugDescription: String {
|
||||
|
||||
return self.cs_dump()
|
||||
}
|
||||
|
||||
|
||||
// MARK: IndentableDebugStringConvertible
|
||||
|
||||
private var cs_dumpInfo: DumpInfo {
|
||||
|
||||
var dumpInfo: DumpInfo = [("entityClass", self.entityClass)]
|
||||
if let extraInfo = self.dumpInfo {
|
||||
|
||||
dumpInfo.append(extraInfo)
|
||||
}
|
||||
return dumpInfo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - ICloudStore
|
||||
|
||||
extension ICloudStore: CustomDebugStringConvertible, IndentableDebugStringConvertible {
|
||||
@@ -318,8 +347,11 @@ extension LocalStorageOptions: CustomDebugStringConvertible, IndentableDebugStri
|
||||
return "[.\(flags[0])]"
|
||||
|
||||
default:
|
||||
let description = "[\n" + flags.joinWithSeparator(",\n")
|
||||
return description.indent(1) + "\n]"
|
||||
var string = "[\n"
|
||||
string.appendContentsOf(flags.joinWithSeparator(",\n"))
|
||||
string.indent(1)
|
||||
string.appendContentsOf("\n]")
|
||||
return string
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -366,17 +398,53 @@ extension MigrationChain: CustomDebugStringConvertible, IndentableDebugStringCon
|
||||
return "[\(paths[0])]"
|
||||
|
||||
default:
|
||||
var dump = "["
|
||||
var string = "["
|
||||
paths.forEach {
|
||||
|
||||
dump.appendContentsOf("\n\($0);")
|
||||
string.appendContentsOf("\n\($0);")
|
||||
}
|
||||
return dump.indent(1) + "\n]"
|
||||
string.indent(1)
|
||||
string.appendContentsOf("\n]")
|
||||
return string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - SaveResult
|
||||
|
||||
extension SaveResult: CustomDebugStringConvertible, IndentableDebugStringConvertible {
|
||||
|
||||
// MARK: CustomDebugStringConvertible
|
||||
|
||||
public var debugDescription: String {
|
||||
|
||||
return self.cs_dump()
|
||||
}
|
||||
|
||||
|
||||
// MARK: IndentableDebugStringConvertible
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
var string: String
|
||||
switch self {
|
||||
|
||||
case .Success(let hasChanges):
|
||||
string = ".Success ("
|
||||
string.appendDumpInfo("hasChanges", hasChanges)
|
||||
|
||||
case .Failure(let error):
|
||||
string = ".Failure ("
|
||||
string.appendDumpInfo("error", error)
|
||||
}
|
||||
string.indent(1)
|
||||
string.appendContentsOf("\n)")
|
||||
return string
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - SQLiteStore
|
||||
|
||||
extension SQLiteStore: CustomDebugStringConvertible, IndentableDebugStringConvertible {
|
||||
@@ -489,9 +557,9 @@ private extension String {
|
||||
return self
|
||||
}
|
||||
|
||||
private func indent(level: Int) -> String {
|
||||
private mutating func indent(level: Int) {
|
||||
|
||||
return self.stringByReplacingOccurrencesOfString("\n", withString: "\n\(String.indention(level))")
|
||||
self = self.stringByReplacingOccurrencesOfString("\n", withString: "\n\(String.indention(level))")
|
||||
}
|
||||
|
||||
private mutating func appendDumpInfo(key: String, _ value: Any) {
|
||||
@@ -540,23 +608,25 @@ private extension IndentableDebugStringConvertible {
|
||||
let value = self.cs_dumpValue
|
||||
let info = self.cs_dumpInfo
|
||||
|
||||
var dump = "(\(self.dynamicType.cs_typeString()))"
|
||||
var string = "(\(self.dynamicType.cs_typeString()))"
|
||||
if !value.isEmpty {
|
||||
|
||||
dump.appendContentsOf(" \(value)")
|
||||
string.appendContentsOf(" \(value)")
|
||||
}
|
||||
if info.isEmpty {
|
||||
|
||||
return dump
|
||||
return string
|
||||
}
|
||||
else {
|
||||
|
||||
dump.appendContentsOf(" {")
|
||||
string.appendContentsOf(" (")
|
||||
info.forEach {
|
||||
|
||||
dump.appendDumpInfo($0, $1)
|
||||
string.appendDumpInfo($0, $1)
|
||||
}
|
||||
return dump.indent(1) + "\n}"
|
||||
string.indent(1)
|
||||
string.appendContentsOf("\n)")
|
||||
return string
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -580,7 +650,9 @@ extension Array: IndentableDebugStringConvertible {
|
||||
|
||||
string.appendContentsOf("\n\(index) = \(formattedValue(item));")
|
||||
}
|
||||
return string.indent(1) + "\n]"
|
||||
string.indent(1)
|
||||
string.appendContentsOf("\n]")
|
||||
return string
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -601,7 +673,9 @@ extension Dictionary: IndentableDebugStringConvertible {
|
||||
|
||||
string.appendContentsOf("\n\(formattedValue(key)) = \(formattedValue(value));")
|
||||
}
|
||||
return string.indent(1) + "\n]"
|
||||
string.indent(1)
|
||||
string.appendContentsOf("\n]")
|
||||
return string
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -610,7 +684,7 @@ extension NSAttributeDescription: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
var string = "{"
|
||||
var string = "("
|
||||
|
||||
string.appendDumpInfo("attributeType", self.attributeType)
|
||||
string.appendDumpInfo("attributeValueClassName", self.attributeValueClassName)
|
||||
@@ -630,7 +704,9 @@ extension NSAttributeDescription: IndentableDebugStringConvertible {
|
||||
string.appendDumpInfo("storedInExternalRecord", self.storedInExternalRecord)
|
||||
string.appendDumpInfo("renamingIdentifier", self.renamingIdentifier)
|
||||
|
||||
return string.indent(1) + "\n}"
|
||||
string.indent(1)
|
||||
string.appendContentsOf("\n)")
|
||||
return string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -683,7 +759,7 @@ extension NSEntityDescription: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
var string = "{"
|
||||
var string = "("
|
||||
string.appendDumpInfo("managedObjectClassName", self.managedObjectClassName!)
|
||||
string.appendDumpInfo("name", self.name)
|
||||
string.appendDumpInfo("abstract", self.abstract)
|
||||
@@ -699,7 +775,9 @@ extension NSEntityDescription: IndentableDebugStringConvertible {
|
||||
|
||||
string.appendDumpInfo("uniquenessConstraints", self.uniquenessConstraints)
|
||||
}
|
||||
return string.indent(1) + "\n}"
|
||||
string.indent(1)
|
||||
string.appendContentsOf("\n)")
|
||||
return string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,22 +785,39 @@ extension NSError: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
var string = "{"
|
||||
var string = "("
|
||||
string.appendDumpInfo("domain", self.domain)
|
||||
string.appendDumpInfo("code", self.code)
|
||||
string.appendDumpInfo("userInfo", self.userInfo)
|
||||
return string.indent(1) + "\n}"
|
||||
string.indent(1)
|
||||
string.appendContentsOf("\n)")
|
||||
return string
|
||||
}
|
||||
}
|
||||
|
||||
//extension NSManagedObject: IndentableDebugStringConvertible {
|
||||
//
|
||||
// private var cs_dumpValue: String {
|
||||
//
|
||||
// // TODO:
|
||||
// var string = "("
|
||||
// // string.appendDumpInfo("self", self)
|
||||
// string.indent(1)
|
||||
// string.appendContentsOf("\n)")
|
||||
// return string
|
||||
// }
|
||||
//}
|
||||
|
||||
extension NSManagedObjectModel: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
var string = "{"
|
||||
var string = "("
|
||||
string.appendDumpInfo("configurations", self.configurations)
|
||||
string.appendDumpInfo("entities", self.entities)
|
||||
return string.indent(1) + "\n}"
|
||||
string.indent(1)
|
||||
string.appendContentsOf("\n)")
|
||||
return string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -738,7 +833,7 @@ extension NSRelationshipDescription: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
var string = "{"
|
||||
var string = "("
|
||||
|
||||
string.appendDumpInfo("destinationEntity", self.destinationEntity?.name)
|
||||
string.appendDumpInfo("inverseRelationship", self.inverseRelationship?.name)
|
||||
@@ -760,7 +855,9 @@ extension NSRelationshipDescription: IndentableDebugStringConvertible {
|
||||
string.appendDumpInfo("storedInExternalRecord", self.storedInExternalRecord)
|
||||
string.appendDumpInfo("renamingIdentifier", self.renamingIdentifier)
|
||||
|
||||
return string.indent(1) + "\n}"
|
||||
string.indent(1)
|
||||
string.appendContentsOf("\n)")
|
||||
return string
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user