github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/ui/app/models/node-attributes.js (about)

     1  import Ember from 'ember';
     2  import attr from 'ember-data/attr';
     3  import Fragment from 'ember-data-model-fragments/fragment';
     4  import flat from 'npm:flat';
     5  
     6  const { computed, get } = Ember;
     7  const { unflatten } = flat;
     8  
     9  export default Fragment.extend({
    10    attributes: attr(),
    11  
    12    attributesStructured: computed('attributes', function() {
    13      // `unflatten` doesn't sort keys before unflattening, so manual preprocessing is necessary.
    14      const original = this.get('attributes');
    15      const attrs = Object.keys(original).sort().reduce((obj, key) => {
    16        obj[key] = original[key];
    17        return obj;
    18      }, {});
    19      return unflatten(attrs, { overwrite: true });
    20    }),
    21  
    22    unknownProperty(key) {
    23      // Returns the exact value in index 0 and the subtree in index 1
    24      //
    25      // ex: nodeAttrs.get('driver.docker')
    26      // [ "1", { version: "17.05.0-ce", volumes: { enabled: "1" } } ]
    27      return get(this.get('attributesStructured'), key);
    28    },
    29  });