Skip to content

Commit

Permalink
Merge pull request #5130 from emberjs/fix-pluralize-singularize
Browse files Browse the repository at this point in the history
Replace Ember.String.{pluralize,singularize} with ember-inflector imports
  • Loading branch information
rwjblue authored Aug 16, 2017
2 parents d67ca67 + bc930ff commit ef9f707
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
6 changes: 4 additions & 2 deletions addon/-private/adapters/build-url-mixin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ember from 'ember';
import { pluralize } from 'ember-inflector';

const get = Ember.get;

Expand Down Expand Up @@ -420,11 +421,12 @@ export default Ember.Mixin.create({
```app/adapters/application.js
import DS from 'ember-data';
import { pluralize } from 'ember-inflector';
export default DS.RESTAdapter.extend({
pathForType: function(modelName) {
var decamelized = Ember.String.decamelize(modelName);
return Ember.String.pluralize(decamelized);
return pluralize(decamelized);
}
});
```
Expand All @@ -435,6 +437,6 @@ export default Ember.Mixin.create({
**/
pathForType(modelName) {
let camelized = Ember.String.camelize(modelName);
return Ember.String.pluralize(camelized);
return pluralize(camelized);
}
});
3 changes: 2 additions & 1 deletion addon/adapters/json-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import Ember from 'ember';
import { pluralize } from 'ember-inflector';
import RESTAdapter from "./rest";
import { isEnabled } from '../-private';
import { deprecate } from '@ember/debug';
Expand Down Expand Up @@ -258,7 +259,7 @@ const JSONAPIAdapter = RESTAdapter.extend({

pathForType(modelName) {
let dasherized = Ember.String.dasherize(modelName);
return Ember.String.pluralize(dasherized);
return pluralize(dasherized);
},

// TODO: Remove this once we have a better way to override HTTP verbs.
Expand Down
3 changes: 2 additions & 1 deletion addon/serializers/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ const JSONSerializer = Serializer.extend({
```app/serializers/application.js
import DS from 'ember-data';
import { singularize } from 'ember-inflector';
export default DS.JSONSerializer.extend({
serialize(snapshot, options) {
Expand Down Expand Up @@ -987,7 +988,7 @@ const JSONSerializer = Serializer.extend({
}
function serverHasManyName(name) {
return serverAttributeName(name.singularize()) + "_IDS";
return serverAttributeName(singularize(name)) + "_IDS";
}
```
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/adapter/build-url-mixin-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import setupStore from 'dummy/tests/helpers/store';
import Ember from 'ember';
import { pluralize } from 'ember-inflector';
import { isEnabled } from 'ember-data/-private';

import {module, test} from 'qunit';
Expand Down Expand Up @@ -184,7 +185,7 @@ test('buildURL - with camelized names', function(assert) {
adapter.setProperties({
pathForType(type) {
let decamelized = Ember.String.decamelize(type);
return Ember.String.underscore(Ember.String.pluralize(decamelized));
return Ember.String.underscore(pluralize(decamelized));
}
});

Expand Down
3 changes: 2 additions & 1 deletion tests/integration/adapter/rest-adapter-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import setupStore from 'dummy/tests/helpers/store';
import Ember from 'ember';
import { singularize } from 'ember-inflector';

import testInDebug from 'dummy/tests/helpers/test-in-debug';
import {module, test} from 'qunit';
Expand Down Expand Up @@ -2069,7 +2070,7 @@ test('normalizeKey - to set up _ids and _id', function(assert) {
let underscored = Ember.String.underscore(rel);
return underscored + '_id';
} else {
let singular = Ember.String.singularize(rel);
let singular = singularize(rel);
return Ember.String.underscore(singular) + '_ids';
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/serializers/rest-serializer-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import setupStore from 'dummy/tests/helpers/store';
import Ember from 'ember';
import { singularize } from 'ember-inflector';

import testInDebug from 'dummy/tests/helpers/test-in-debug';
import {module, test} from 'qunit';
Expand Down Expand Up @@ -104,7 +105,7 @@ test("normalizeResponse with custom modelNameFromPayloadKey", function(assert) {

env.restSerializer.modelNameFromPayloadKey = function(root) {
var camelized = Ember.String.camelize(root);
return Ember.String.singularize(camelized);
return singularize(camelized);
};
env.registry.register('serializer:home-planet', DS.JSONSerializer);
env.registry.register('serializer:super-villain', DS.JSONSerializer);
Expand Down Expand Up @@ -256,7 +257,7 @@ testInDebug("normalizeResponse warning with custom modelNameFromPayloadKey", fun

// should not warn if a model is found.
env.restSerializer.modelNameFromPayloadKey = function(root) {
return Ember.String.camelize(Ember.String.singularize(root));
return Ember.String.camelize(singularize(root));
};

jsonHash = {
Expand Down

0 comments on commit ef9f707

Please sign in to comment.