<commit_before>//
//  RealmCache.swift
//  RealmCache
//
//  Created by Alex on 10/05/2015.
//  Copyright (c) 2015 PANAXIOM Ltd. All rights reserved.
//

import Foundation
import RealmSwift

public class RealmCache {

    static let defaultCacheName = "cache"

    let name: String
    let realm: Realm

    private static func cachesDirectory() -> String {
        let paths = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true) as! [String]
        return paths[0]
    }

    private static func migrate(path: String) {
        setSchemaVersion(1, path) { (migration, oldSchemaVersion) -> Void in
        }
    }

    public init(name: String = defaultCacheName) {
        self.name = name + ".realm"
        let path = RealmCache.cachesDirectory() + name
        RealmCache.migrate(path)
        self.realm = Realm(path: path)
    }

    deinit {
        realm.invalidate()
    }<commit_msg>Use default realm version if available<commit_after>//
//  RealmCache.swift
//  RealmCache
//
//  Created by Alex on 10/05/2015.
//  Copyright (c) 2015 PANAXIOM Ltd. All rights reserved.
//

import Foundation
import RealmSwift

public class RealmCache {

    static let defaultCacheName = "cache"

    let name: String
    let realm: Realm

    private static func cachesDirectory() -> String {
        let paths = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true) as! [String]
        return paths[0]
    }

    private static func migrate(path: String) {
        let realmCacheSchemaVersion: UInt = 1

        let defaultRealmSchemaVersion = schemaVersionAtPath(Realm.defaultPath)

        let schemaVersion = defaultRealmSchemaVersion ?? realmCacheSchemaVersion

        setSchemaVersion(schemaVersion, path) { (migration, oldSchemaVersion) -> Void in
        }
    }

    public init(name: String = defaultCacheName) {
        self.name = name + ".realm"
        let path = RealmCache.cachesDirectory() + name
        RealmCache.migrate(path)
        self.realm = Realm(path: path)
    }

    deinit {
        realm.invalidate()
    }
{'fraction_non_alphanumeric': 0.09452975047984645, 'fraction_numerical': 0.013435700575815739, 'mean_word_length': 2.677248677248677, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7218949', 'n_tokens_mistral': 657, 'n_tokens_neox': 611, 'n_words': 166}