Skip to content

Instantly share code, notes, and snippets.

@sedouard
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sedouard/2b827ca4525a3f00b812 to your computer and use it in GitHub Desktop.
Save sedouard/2b827ca4525a3f00b812 to your computer and use it in GitHub Desktop.
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