<commit_before>import Ember from 'ember';
import attributeMeta from 'gatemedia-data/utils/attribute-meta';
import tooling from 'gatemedia-data/utils/tooling';

export default function (type, options) {
  options = options || {};
  var meta = attributeMeta(type, options);

  return Ember.computed({
    get: function(key) {
      var value = this.get('_data.' + meta.codec.key(key));

      tooling.readAttribute(this, key, value);
      if (Ember.isNone(value)) {
        var data = this.get('_data');
        if ((data && data.hasOwnProperty(meta.codec.key(key))) || options.defaultUndefined) {
          value = options.defaultValue;
        } else {
          var id = this.get('_data.id');
          if (id) {
            Ember.Logger.warn(Ember.String.fmt('Accessing undefined attribute %@[%@].%@ - Fetch full resource',
              this.constructor, id, key));
            this.reload({ /*useContext: false,*/ sync: true });
            value = this.get('_data.' + meta.codec.key(key));
          } else {
            Ember.Logger.info(Ember.String.fmt('New %@ instance, use default %@',
              this.constructor, key));
            value = options.defaultValue;
          }
        }
      }
      value = meta.codec.decode(value);
      return value;
    },
    set: function(key, value, oldValue) {
      var encodedValue = meta.codec.encode(value);
      this._changeAttribute(key, oldValue, encodedValue);
      this.set('_data.' + meta.codec.key(key), encodedValue);
      return value;
    }
  }).property('_data', '_cacheTimestamp').meta(meta);
}<commit_msg>Avoid dirtying model if change is iso<commit_after>import Ember from 'ember';
import attributeMeta from 'gatemedia-data/utils/attribute-meta';
import tooling from 'gatemedia-data/utils/tooling';

export default function (type, options) {
  options = options || {};
  var meta = attributeMeta(type, options);

  return Ember.computed({
    get: function(key) {
      var value = this.get('_data.' + meta.codec.key(key));

      tooling.readAttribute(this, key, value);
      if (Ember.isNone(value)) {
        var data = this.get('_data');
        if ((data && data.hasOwnProperty(meta.codec.key(key))) || options.defaultUndefined) {
          value = options.defaultValue;
        } else {
          var id = this.get('_data.id');
          if (id) {
            Ember.Logger.warn(Ember.String.fmt('Accessing undefined attribute %@[%@].%@ - Fetch full resource',
              this.constructor, id, key));
            this.reload({ /*useContext: false,*/ sync: true });
            value = this.get('_data.' + meta.codec.key(key));
          } else {
            Ember.Logger.info(Ember.String.fmt('New %@ instance, use default %@',
              this.constructor, key));
            value = options.defaultValue;
          }
        }
      }
      value = meta.codec.decode(value);
      return value;
    },
    set: function(key, value, oldValue) {
      if (value !== oldValue) {
        var encodedValue = meta.codec.encode(value);
        this._changeAttribute(key, oldValue, encodedValue);
        this.set('_data.' + meta.codec.key(key), encodedValue);
      }
      return value;
    }
  }).property('_data', '_cacheTimestamp').meta(meta);
}
{'fraction_non_alphanumeric': 0.15129950495049505, 'fraction_numerical': 0.0, 'mean_word_length': 2.510314875135722, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6780310', 'n_tokens_mistral': 963, 'n_tokens_neox': 958, 'n_words': 205}