<commit_before>import Foundation

public typealias ExecutionClosure = () -> Void

private let MigrationLastVersionKey = "Migration.lastMigrationVersion"
private let MigrationLastAppVersionKey = "Migration.lastAppVersion"

private let MigrationLastBuildKey = "Migration.lastMigrationBuild"
private let MigrationLastAppBuildKey = "Migration.lastAppBuild"

public struct Migration {
    
    static var AppBundle: NSBundle = NSBundle.mainBundle()
    
    public static func migrateToVersion(version: String, closure: ExecutionClosure) {
        if version.compare(self.lastMigrationVersion, options: [.NumericSearch]) == .OrderedDescending &&
            version.compare(self.appVersion, options: [.NumericSearch]) != .OrderedDescending {
                closure()
                self.setLastMigrationVersion(version)
        }
    }
    
    public static func migrateToBuild(build: String, closure: ExecutionClosure) {
        if build.compare(self.lastMigrationBuild, options: [.NumericSearch]) == .OrderedDescending &&
            build.compare(self.appBuild, options: [.NumericSearch]) != .OrderedDescending {
                closure()
                self.setLastMigrationBuild(build)
        }
    }
    
    public static func applicationUpdate(closure: ExecutionClosure) {
        if self.lastAppVersion != self.appVersion {
            closure()
            self.setLastAppVersion(self.appVersion)
        }
    }
    
    public static func buildNumberUpdate(closure: ExecutionClosure) {
        if self.lastAppBuild != self.appBuild {
            closure()
            self.setLastAppBuild(self.appBuild)
        }
    }
    
    public static func reset() {
        self.setLastAppVersion(nil)
        self.setLastMigrationVersion(nil)
        self.setLastAppBuild(nil)
        self.setLastMigrationBuild(nil)
        
        print("self.lastAppVersion: \(self.lastAppVersion)")
        print("self.lastMigrationVersion: \(self.lastMigrationVersion)")
        print("self.lastAppBuild: \(self.lastAppBuild)")
        print("self.lastMigrationBuild: \(self.lastMigrationBuild)")
    }
    
    // MARK: - Private methods and properties
    
    private static var appVersion: String {
        return Migration.AppBundle.objectForInfoDictionaryKey("CFBundleShortVersionString") as? String ?? ""
    }
    
    private static var appBuild: String {
        return Migration.AppBundle.objectForInfoDictionaryKey("CFBundleVersion") as? String ?? ""
    }
    
    private static func setLastMigrationVersion(version: String?) {
        NSUserDefaults.standardUserDefaults().setValue(version, forKey: MigrationLastVersionKey)
        NSUserDefaults.standardUserDefaults().synchronize()
    }
    
    private static func setLastMigrationBuild(build: String?) {
        NSUserDefaults.standardUserDefaults().setValue(build, forKey: MigrationLastBuildKey)
        NSUserDefaults.standardUserDefaults().synchronize()
    }
    
    private static var lastMigrationVersion: String {
        return NSUserDefaults.standardUserDefaults().valueForKey(MigrationLastVersionKey) as? String ?? ""
    }
    
    private static var lastMigrationBuild: String {
        return NSUserDefaults.standardUserDefaults().valueForKey(MigrationLastBuildKey) as? String ?? ""
    }
    
    private static func setLastAppVersion(version: String?) {<commit_msg>Removed debug logs.<commit_after>import Foundation

public typealias ExecutionClosure = () -> Void

private let MigrationLastVersionKey = "Migration.lastMigrationVersion"
private let MigrationLastAppVersionKey = "Migration.lastAppVersion"

private let MigrationLastBuildKey = "Migration.lastMigrationBuild"
private let MigrationLastAppBuildKey = "Migration.lastAppBuild"

public struct Migration {
    
    static var AppBundle: NSBundle = NSBundle.mainBundle()
    
    public static func migrateToVersion(version: String, closure: ExecutionClosure) {
        if version.compare(self.lastMigrationVersion, options: [.NumericSearch]) == .OrderedDescending &&
            version.compare(self.appVersion, options: [.NumericSearch]) != .OrderedDescending {
                closure()
                self.setLastMigrationVersion(version)
        }
    }
    
    public static func migrateToBuild(build: String, closure: ExecutionClosure) {
        if build.compare(self.lastMigrationBuild, options: [.NumericSearch]) == .OrderedDescending &&
            build.compare(self.appBuild, options: [.NumericSearch]) != .OrderedDescending {
                closure()
                self.setLastMigrationBuild(build)
        }
    }
    
    public static func applicationUpdate(closure: ExecutionClosure) {
        if self.lastAppVersion != self.appVersion {
            closure()
            self.setLastAppVersion(self.appVersion)
        }
    }
    
    public static func buildNumberUpdate(closure: ExecutionClosure) {
        if self.lastAppBuild != self.appBuild {
            closure()
            self.setLastAppBuild(self.appBuild)
        }
    }
    
    public static func reset() {
        self.setLastAppVersion(nil)
        self.setLastMigrationVersion(nil)
        self.setLastAppBuild(nil)
        self.setLastMigrationBuild(nil)
    }
    
    // MARK: - Private methods and properties
    
    private static var appVersion: String {
        return Migration.AppBundle.objectForInfoDictionaryKey("CFBundleShortVersionString") as? String ?? ""
    }
    
    private static var appBuild: String {
        return Migration.AppBundle.objectForInfoDictionaryKey("CFBundleVersion") as? String ?? ""
    }
    
    private static func setLastMigrationVersion(version: String?) {
        NSUserDefaults.standardUserDefaults().setValue(version, forKey: MigrationLastVersionKey)
        NSUserDefaults.standardUserDefaults().synchronize()
    }
    
    private static func setLastMigrationBuild(build: String?) {
        NSUserDefaults.standardUserDefaults().setValue(build, forKey: MigrationLastBuildKey)
        NSUserDefaults.standardUserDefaults().synchronize()
    }
    
    private static var lastMigrationVersion: String {
        return NSUserDefaults.standardUserDefaults().valueForKey(MigrationLastVersionKey) as? String ?? ""
    }
    
    private static var lastMigrationBuild: String {
        return NSUserDefaults.standardUserDefaults().valueForKey(MigrationLastBuildKey) as? String ?? ""
    }
    
    private static func setLastAppVersion(version: String?) {
{'fraction_non_alphanumeric': 0.08884393962968726, 'fraction_numerical': 0.0, 'mean_word_length': 3.1605177993527507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '6624864', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1677, 'n_words': 326}