Skip to content

Commit

Permalink
Merge pull request #147 from Yogeswar/sleb-87
Browse files Browse the repository at this point in the history
Change ember.assert to Ember.Error, Closes #87
  • Loading branch information
notmessenger committed Nov 16, 2015
2 parents 7b8bd43 + 8b16d29 commit 8069351
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions addon/services/sl-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,38 @@ export default Ember.Service.extend({
* @param {String} activity
* @param {String} resource
* @param {Boolean} possible
* @throws {ember.assert} If no parameters provided, first parameter is not a string, second parameter is not a
* @throws {ember/Error} If no parameters provided, first parameter is not a string, second parameter is not a
* string, or third parameter is not a boolean or undefined
* @returns {Boolean}
*/
isAble( activity, resource, possible ) {
Ember.assert(
'services/sl-behavior.isAble() expects at least two parameters to be provided',
activity && resource
);
if ( Ember.isEmpty( activity ) &&
Ember.isEmpty( resource ) ) {
throw new Ember.Error(
'services/sl-behavior.isAble() expects at least two parameters to be provided'
);
}

const behaviors = this.get( 'behaviors' );

Ember.assert(
'services/sl-behavior.isAble() expects `activity` parameter to be a String',
'string' === Ember.typeOf( activity )
);
if ( 'string' !== Ember.typeOf( activity ) ) {
throw new Ember.Error(
'services/sl-behavior.isAble() expects `activity` parameter to be a String'
);
}

Ember.assert(
'services/sl-behavior.isAble() expects `resource` parameter to be a String',
'string' === Ember.typeOf( resource )
);
if ( 'string' !== Ember.typeOf( resource ) ) {
throw new Ember.Error(
'services/sl-behavior.isAble() expects `resource` parameter to be a String'
);
}

Ember.assert(
'services/sl-behavior.isAble() expects `possible` parameter to be a Boolean or undefined',
'boolean' === Ember.typeOf( possible ) ||
'undefined' === Ember.typeOf( possible )
);
if ( 'boolean' !== Ember.typeOf( possible ) &&
'undefined' !== Ember.typeOf( possible ) ) {
throw new Ember.Error(
'services/sl-behavior.isAble() expects `possible` parameter to be a Boolean or undefined'
);
}

if ( 'undefined' === Ember.typeOf( possible ) ) {
possible = true;
Expand Down Expand Up @@ -107,19 +112,18 @@ export default Ember.Service.extend({
*
* @function
* @param {Object} behaviors
* @throws {ember.assert} If argument is not an object
* @throws {ember/Error} If argument is not an object
* @returns {undefined}
*/
setBehaviors( behaviors ) {
/* jshint ignore:start */
Ember.assert(
'services/sl-behavior.setBehaviors() expects "behaviors" parameter to be an Object',
(
'instance' === Ember.typeOf( behaviors ) ||
'object' === Ember.typeOf( behaviors )
) &&
'symbol' !== typeof behaviors
);
if ( ( 'instance' !== Ember.typeOf( behaviors ) &&
'object' !== Ember.typeOf( behaviors ) ) ||
'symbol' === typeof behaviors ) {
throw new Ember.Error(
'services/sl-behavior.setBehaviors() expects "behaviors" parameter to be an Object'
);
}
/* jshint ignore:end */

this.set( 'behaviors', behaviors );
Expand Down

0 comments on commit 8069351

Please sign in to comment.