From bc930ff85b948e96eaf23edd6a74004695b60edd Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Wed, 16 Aug 2017 14:53:28 +0100 Subject: [PATCH] Replace Ember.String.{pluralize,singularize} with ember-inflector imports --- addon/-private/adapters/build-url-mixin.js | 6 ++++-- addon/adapters/json-api.js | 3 ++- addon/serializers/json.js | 3 ++- tests/integration/adapter/build-url-mixin-test.js | 3 ++- tests/integration/adapter/rest-adapter-test.js | 3 ++- tests/integration/serializers/rest-serializer-test.js | 5 +++-- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/addon/-private/adapters/build-url-mixin.js b/addon/-private/adapters/build-url-mixin.js index bd3de1ce3e1..0273992da8c 100644 --- a/addon/-private/adapters/build-url-mixin.js +++ b/addon/-private/adapters/build-url-mixin.js @@ -1,4 +1,5 @@ import Ember from 'ember'; +import { pluralize } from 'ember-inflector'; const get = Ember.get; @@ -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); } }); ``` @@ -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); } }); diff --git a/addon/adapters/json-api.js b/addon/adapters/json-api.js index 144e15caa69..48610dec134 100644 --- a/addon/adapters/json-api.js +++ b/addon/adapters/json-api.js @@ -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'; @@ -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. diff --git a/addon/serializers/json.js b/addon/serializers/json.js index f624bd43f1f..8547a42f886 100644 --- a/addon/serializers/json.js +++ b/addon/serializers/json.js @@ -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) { @@ -987,7 +988,7 @@ const JSONSerializer = Serializer.extend({ } function serverHasManyName(name) { - return serverAttributeName(name.singularize()) + "_IDS"; + return serverAttributeName(singularize(name)) + "_IDS"; } ``` diff --git a/tests/integration/adapter/build-url-mixin-test.js b/tests/integration/adapter/build-url-mixin-test.js index aee911e6f6f..f3adddc18f2 100644 --- a/tests/integration/adapter/build-url-mixin-test.js +++ b/tests/integration/adapter/build-url-mixin-test.js @@ -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'; @@ -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)); } }); diff --git a/tests/integration/adapter/rest-adapter-test.js b/tests/integration/adapter/rest-adapter-test.js index 403b14e4545..7f36d338b6a 100644 --- a/tests/integration/adapter/rest-adapter-test.js +++ b/tests/integration/adapter/rest-adapter-test.js @@ -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'; @@ -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'; } } diff --git a/tests/integration/serializers/rest-serializer-test.js b/tests/integration/serializers/rest-serializer-test.js index b9b2cb6b60e..5f3f912d072 100644 --- a/tests/integration/serializers/rest-serializer-test.js +++ b/tests/integration/serializers/rest-serializer-test.js @@ -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'; @@ -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); @@ -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 = {