Last active
August 29, 2015 14:19
-
-
Save sedouard/2b827ca4525a3f00b812 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
var azureStorage = null; | |
var fs = null; | |
// check if running in nw, if not, we're probably running as a test | |
// in which case this entire service will be mocked | |
if (window.requireNode) { | |
azureStorage = window.requireNode('azure-storage'); | |
fs = window.requireNode('fs'); | |
} | |
export default Ember.Service.extend({ | |
azureStorage: azureStorage, | |
fs: fs, | |
getActiveAccount: function (store) { | |
return new Ember.RSVP.Promise(function (resolve, reject) { | |
var accounts = store.all('account'), | |
length = accounts.get('length'), | |
i = 0; | |
accounts.forEach(function (account) { | |
if (account.get('active')** === true) { | |
return Ember.run(null, resolve, account); | |
} | |
i += 1; | |
if (i >= length) { | |
return Ember.run(null, reject, 'could not find any active accounts'); | |
} | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment