5
votes

Where/how can i adjust the Ember.Inflector Class / create an instance of it that ember-cli picks up?

Thanks!

3

3 Answers

6
votes

I placed it in the model file and it worked fine:

import DS from 'ember-data';
import Ember from 'ember';

var inflector = Ember.Inflector.inflector;
inflector.irregular('nota', 'notas');
inflector.singular(/nota/, 'nota');

export default DS.Model.extend({
  title: DS.attr('string'),
  description: DS.attr('string'),
  language: DS.attr('string'),
  body: DS.attr('string')
});
10
votes

I generated an initializer and put this data there. This ensures it loads before anything that might need it. Like the model, adapter, or serializer.

initializers/inflector.js

import Ember from 'ember';
export function initialize(/* container, application */) {
  var inflector = Ember.Inflector.inflector;
  inflector.uncountable('aamc-pcrs');
}

export default {
  name: 'inflector',
  initialize: initialize
};
0
votes

The Ember Guides covers this in Models - Customizing Adapters:

Create the file app/models/custom-inflector-rules.js:

import Inflector from 'ember-inflector';

const inflector = Inflector.inflector;

inflector.irregular('formula', 'formulae');
inflector.uncountable('advice');

// Meet Ember Inspector's expectation of an export
export default {};

Then in app/app.js add the line:

import './models/custom-inflector-rules';

And if you want to use this in a unit test for a serializer/adapter then you can just import the custom-inflector-rules file into the test.