OSDN Git Service

staticプロパティをインスタンスプロパティに変更
[kcd/KCD.git] / KCD / ResourceHistoryDataStore.swift
index d04d465..afbd510 100644 (file)
@@ -7,23 +7,14 @@
 //
 
 import Cocoa
+import Doutaku
 
-extension CoreDataConfiguration {
+final class ResourceHistoryDataStore: CoreDataManager {
     
-    static let resourceHistory = CoreDataConfiguration("ResourceHistory")
-}
-
-final class ResourceHistoryDataStore: CoreDataAccessor, CoreDataManager {
-    
-    static let core = CoreDataCore(.resourceHistory)
+    static let core = CoreDataCore(CoreDataConfiguration("ResourceHistory"))
     
     static let `default` = ResourceHistoryDataStore(type: .reader)
     
-    class func oneTimeEditor() -> ResourceHistoryDataStore {
-        
-        return ResourceHistoryDataStore(type: .editor)
-    }
-    
     required init(type: CoreDataManagerType) {
         
         context = ResourceHistoryDataStore.context(for: type)
@@ -31,27 +22,8 @@ final class ResourceHistoryDataStore: CoreDataAccessor, CoreDataManager {
     
     deinit {
         
-        save()
+        save(errorHandler: presentOnMainThread)
     }
     
     let context: NSManagedObjectContext
 }
-
-extension ResourceHistoryDataStore {
-    
-    func resources(in minites: [Int], older: Date) -> [Resource] {
-        
-        let p = NSPredicate.empty
-            .and(NSPredicate(#keyPath(Resource.minute), valuesIn: minites))
-            .and(NSPredicate(#keyPath(Resource.date), lessThan: older))
-        
-        guard let resources = try? objects(of: Resource.entity, predicate: p) else { return [] }
-        
-        return resources
-    }
-    
-    func createResource() -> Resource? {
-        
-        return insertNewObject(for: Resource.entity)
-    }
-}