<commit_before>//
//  CurrentUser.swift
//  CloudKitCurrentUser
//
//  Created by <NAME> on 2016-12-02.
//  Copyright © 2016 JagCesar. All rights reserved.
//

import Foundation

public class CurrentUser {
    public static let sharedInstance = CurrentUser()
    public static let statusChangedNotification: NSNotification.Name = NSNotification.Name("CurrentUserStatusChanged")

    private var status: CurrentUserStatus = .NotDetermined
    private var isLoadingStatus: Bool = false
    private var statusCompletionBlocks: [StatusCompletionBlock] = []

    private var userIdentifier: String?
    private var isLoadingUserIdentifier: Bool = false
    private var userIdentifierCompletionBlocks: [UserIdentifierCompletionBlock] = []
    private let userRequestObject: CurrentUserRequestProtocol

    init() {
        userRequestObject = CloudKitCurrentUserRequest()

        NotificationCenter.default.addObserver(self,
                                               selector: #selector(CurrentUser.statusChanged),
                                               name: NSNotification.Name.CKAccountChanged,
                                               object: nil)
    }

    deinit {
        NotificationCenter.default.removeObserver(self)
    }

    public func currentStatus(forcedReload: Bool = false, completionBlock: @escaping StatusCompletionBlock) {
        guard forcedReload || status == .NotDetermined else {
            DispatchQueue.main.async {
                completionBlock(self.status, nil)
            }
            return
        }
        statusCompletionBlocks.append(completionBlock)
        guard !isLoadingStatus || forcedReload else { return }
        isLoadingStatus = true

        userRequestObject.currentStatus { accountStatus, error in
            self.status = accountStatus

            self.isLoadingStatus = false

            for completionBlock in self.statusCompletionBlocks {
                DispatchQueue.main.async {<commit_msg>Makes CurrentUser more singleton Makes the init function private, so nobody can create a new instance of CurrentUser<commit_after>//
//  CurrentUser.swift
//  CloudKitCurrentUser
//
//  Created by <NAME> on 2016-12-02.
//  Copyright © 2016 JagCesar. All rights reserved.
//

import Foundation

public class CurrentUser {
    public static let sharedInstance = CurrentUser()
    public static let statusChangedNotification: NSNotification.Name = NSNotification.Name("CurrentUserStatusChanged")

    private var status: CurrentUserStatus = .NotDetermined
    private var isLoadingStatus: Bool = false
    private var statusCompletionBlocks: [StatusCompletionBlock] = []

    private var userIdentifier: String?
    private var isLoadingUserIdentifier: Bool = false
    private var userIdentifierCompletionBlocks: [UserIdentifierCompletionBlock] = []
    private let userRequestObject: CurrentUserRequestProtocol

    init() {
        userRequestObject = CloudKitCurrentUserRequest()

    private init() {
        NotificationCenter.default.addObserver(self,
                                               selector: #selector(CurrentUser.statusChanged),
                                               name: NSNotification.Name.CKAccountChanged,
                                               object: nil)
    }

    deinit {
        NotificationCenter.default.removeObserver(self)
    }

    public func currentStatus(forcedReload: Bool = false, completionBlock: @escaping StatusCompletionBlock) {
        guard forcedReload || status == .NotDetermined else {
            DispatchQueue.main.async {
                completionBlock(self.status, nil)
            }
            return
        }
        statusCompletionBlocks.append(completionBlock)
        guard !isLoadingStatus || forcedReload else { return }
        isLoadingStatus = true

        userRequestObject.currentStatus { accountStatus, error in
            self.status = accountStatus

            self.isLoadingStatus = false

            for completionBlock in self.statusCompletionBlocks {
                DispatchQueue.main.async {
{'fraction_non_alphanumeric': 0.06640432857845549, 'fraction_numerical': 0.005902606984751598, 'mean_word_length': 2.4436917866215073, 'pattern_counts': {'":': 0, '<': 5, '<?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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5379072', 'n_tokens_mistral': 952, 'n_tokens_neox': 882, 'n_words': 243}