<commit_before>//
//  CoreDataStack.swift
//  CoreDataSMS
//
//  Created by <NAME> on 12/8/14.
//  Copyright (c) 2014 Big Nerd Ranch. All rights reserved.
//

import Foundation
import CoreData

// TODO: rcedwards These will be replaced with Box/Either or something native to Swift (fingers crossed) https://github.com/bignerdranch/CoreDataStack/issues/10

// MARK: - Operation Result Types
public enum CoordinatorResult {
    case Success(NSPersistentStoreCoordinator)
    case Failure(ErrorType)
}
public enum BatchContextResult {
    case Success(NSManagedObjectContext)
    case Failure(ErrorType)
}
public enum SetupResult {
    case Success(CoreDataStack)
    case Failure(ErrorType)
}
public enum SuccessResult {
    case Success
    case Failure(ErrorType)
}
public typealias SaveResult = SuccessResult
public typealias ResetResult = SuccessResult

// MARK: - Action callbacks
public typealias CoreDataStackSetupCallback = SetupResult -> Void
public typealias CoreDataStackStoreResetCallback = ResetResult -> Void
public typealias CoreDataStackBatchMOCCallback = BatchContextResult -> Void

// MARK: - Error Handling
public enum CoreDataStackError: ErrorType {
    case StoreNotFoundAtURL(url: NSURL)
    case InMemoryStoreMissing
}

/**
Three layer CoreData stack comprised of:

* A primary background queue context with a persistent store coordinator
* A main queue context that is a child of the primary queue
* A method for spawning many background worker contexts that are children of the main queue context

Calling save() on any NSMangedObjectContext belonging to the stack will automatically bubble the changes all the way to the NSPersistentStore<commit_msg>Document CoreDataStack enums.<commit_after>//
//  CoreDataStack.swift
//  CoreDataSMS
//
//  Created by <NAME> on 12/8/14.
//  Copyright (c) 2014 Big Nerd Ranch. All rights reserved.
//

import Foundation
import CoreData

// TODO: rcedwards These will be replaced with Box/Either or something native to Swift (fingers crossed) https://github.com/bignerdranch/CoreDataStack/issues/10

// MARK: - Operation Result Types

/// Result containing either an instance of NSPersistentStoreCoordinator or ErrorType
public enum CoordinatorResult {
    /// A success case with associated NSPersistentStoreCoordinator instance
    case Success(NSPersistentStoreCoordinator)
    /// A failure case with associated ErrorType instance
    case Failure(ErrorType)
}
/// Result containing either an instance of NSManagedObjectContext or ErrorType
public enum BatchContextResult {
    /// A success case with associated NSManagedObjectContext instance
    case Success(NSManagedObjectContext)
    /// A failure case with associated ErrorType instance
    case Failure(ErrorType)
}
/// Result containing either an instance of CoreDataStack or ErrorType
public enum SetupResult {
    /// A success case with associated CoreDataStack instance
    case Success(CoreDataStack)
    /// A failure case with associated ErrorType instance
    case Failure(ErrorType)
}
/// Result of void representing success or an instance of ErrorType
public enum SuccessResult {
    /// A success case
    case Success
    /// A failure case with associated ErrorType instance
    case Failure(ErrorType)
}
public typealias SaveResult = SuccessResult
public typealias ResetResult = SuccessResult

// MARK: - Action callbacks
public typealias CoreDataStackSetupCallback = SetupResult -> Void
public typealias CoreDataStackStoreResetCallback = ResetResult -> Void
public typealias CoreDataStackBatchMOCCallback = BatchContextResult -> Void

// MARK: - Error Handling

/// CoreDataStack specific ErrorTypes
public enum CoreDataStackError: ErrorType {
    /// Case when an NSPersistentStore is not found for the supplied store URL
    case StoreNotFoundAtURL(url: NSURL)
    /// Case when an In-Memory store is not found
    case InMemoryStoreMissing
}

/**
Three layer CoreData stack comprised of:

* A primary background queue context with a persistent store coordinator
* A main queue context that is a child of the primary queue
* A method for spawning many background worker contexts that are children of the main queue context

Calling save() on any NSMangedObjectContext belonging to the stack will automatically bubble the changes all the way to the NSPersistentStore
{'fraction_non_alphanumeric': 0.057866604694399255, 'fraction_numerical': 0.005112712061352545, 'mean_word_length': 4.255189255189255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2210008', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1060, 'n_words': 455}