ember-resourceful-rails 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/ember-resourceful-rails/version.rb +1 -1
- data/vendor/assets/javascripts/ember-resourceful.js +317 -306
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,15 +1,15 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            !binary "U0hBMQ==":
         | 
| 3 3 | 
             
              metadata.gz: !binary |-
         | 
| 4 | 
            -
                 | 
| 4 | 
            +
                NDYwNzRkNDJmNGVmNjQ4OWNjNjQ5ZWYzMTI3YjcwNjgyMzBiNjllYg==
         | 
| 5 5 | 
             
              data.tar.gz: !binary |-
         | 
| 6 | 
            -
                 | 
| 6 | 
            +
                M2VhYWRjZjI3MzMxYTA4ZGM2MTk2OThjZWE2MGJlYjRhNWQ2MjI4NQ==
         | 
| 7 7 | 
             
            !binary "U0hBNTEy":
         | 
| 8 8 | 
             
              metadata.gz: !binary |-
         | 
| 9 | 
            -
                 | 
| 10 | 
            -
                 | 
| 11 | 
            -
                 | 
| 9 | 
            +
                Y2RmYTI2ZjkwZTVjNTk0Mjk1NTgxZjdiZDViMWU3N2QzNDRmMWEwOGNlZDkx
         | 
| 10 | 
            +
                OGJkNjQwNTBiYzczNDE1ZmE1NDU1ZjZkOGNhYzgxZjRjYjAwYTY5MTBiZmI0
         | 
| 11 | 
            +
                MTQ3ZjRmNjA1N2EwNzBlYjY3OWNhNDE3YjIzYWUyNDZlYzhhNDM=
         | 
| 12 12 | 
             
              data.tar.gz: !binary |-
         | 
| 13 | 
            -
                 | 
| 14 | 
            -
                 | 
| 15 | 
            -
                 | 
| 13 | 
            +
                Mzg4MmZmMDg1NDU1MTE5NDhiODc1ZmM5MTQ4Y2FmZjgzN2ViZDY4ODk3YmI3
         | 
| 14 | 
            +
                OGI5ODE3ZWU4YmMzMzEyNTEwNjQ0MWFhNWE1NzFhMTQ3NjBhNmNlMThmODc3
         | 
| 15 | 
            +
                NjYzMGQ4MmRiMjBiNjNhODk4YTY4NjE0ZTlkNWE1OGJjNzMyZWI=
         | 
| @@ -1,401 +1,412 @@ | |
| 1 | 
            -
            /*
         | 
| 2 | 
            -
             *   Ember Resourceful 0.0.1
         | 
| 3 | 
            -
             *
         | 
| 4 | 
            -
             *   Copyright (c) 2012-2013 Dan Martens
         | 
| 5 | 
            -
             *   http://danmartens.com
         | 
| 6 | 
            -
             *
         | 
| 7 | 
            -
             *   Permission is hereby granted, free of charge, to any person obtaining 
         | 
| 8 | 
            -
             *   a copy of this software and associated documentation files (the 
         | 
| 9 | 
            -
             *   "Software"), to deal in the Software without restriction, including 
         | 
| 10 | 
            -
             *   without limitation the rights to use, copy, modify, merge, publish, 
         | 
| 11 | 
            -
             *   distribute, sublicense, and/or sell copies of the Software, and to 
         | 
| 12 | 
            -
             *   permit persons to whom the Software is furnished to do so, subject to 
         | 
| 13 | 
            -
             *   the following conditions:
         | 
| 14 | 
            -
             *
         | 
| 15 | 
            -
             *   The above copyright notice and this permission notice shall be 
         | 
| 16 | 
            -
             *   included in all copies or substantial portions of the Software.
         | 
| 17 | 
            -
             *
         | 
| 18 | 
            -
             *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
         | 
| 19 | 
            -
             *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
         | 
| 20 | 
            -
             *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
         | 
| 21 | 
            -
             *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
         | 
| 22 | 
            -
             *   LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
         | 
| 23 | 
            -
             *   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
         | 
| 24 | 
            -
             *   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
         | 
| 25 | 
            -
             */
         | 
| 1 | 
            +
            /* Ember Resourceful v0.0.3 */
         | 
| 26 2 |  | 
| 27 3 | 
             
            (function() {
         | 
| 28 | 
            -
              window.Resourceful = {};
         | 
| 29 | 
            -
             | 
| 30 | 
            -
              Resourceful.Resource = Ember.Object.extend({
         | 
| 31 | 
            -
                resourceAdapter: null,
         | 
| 32 | 
            -
                resourceProperties: null,
         | 
| 33 | 
            -
                resourceUrl: null,
         | 
| 34 | 
            -
                serializers: null,
         | 
| 35 | 
            -
                deserializers: null,
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                isFetching: false,
         | 
| 38 | 
            -
                isFetched: false,
         | 
| 39 | 
            -
                isSaving: false,
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                init: function() {
         | 
| 42 | 
            -
                  var _this = this;
         | 
| 43 | 
            -
             | 
| 44 | 
            -
                  this.persistedProperties = {};
         | 
| 45 | 
            -
                  this.dirtyProperties = [];
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                  this._super();
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                  if (this.resourceProperties) {
         | 
| 50 | 
            -
                    this.resourceProperties.forEach(function(key) {
         | 
| 51 | 
            -
                      _this.addObserver(key, function() {
         | 
| 52 | 
            -
                        if (_this.get(key) !== _this.persistedProperties[key]) {
         | 
| 53 | 
            -
                          if (!_this.dirtyProperties.contains(key)) {
         | 
| 54 | 
            -
                            _this.dirtyProperties.pushObject(key);
         | 
| 55 | 
            -
                          }
         | 
| 56 | 
            -
                        } else {
         | 
| 57 | 
            -
                          _this.dirtyProperties.removeObject(key);
         | 
| 58 | 
            -
                        }
         | 
| 59 | 
            -
                      });
         | 
| 60 | 
            -
                    });
         | 
| 61 | 
            -
                  }
         | 
| 62 | 
            -
                },
         | 
| 63 | 
            -
             | 
| 64 | 
            -
                isNew: function() {
         | 
| 65 | 
            -
                  return this.get('id') === undefined;
         | 
| 66 | 
            -
                }.property('id'),
         | 
| 67 4 |  | 
| 68 | 
            -
             | 
| 69 | 
            -
                  return this.get('dirtyProperties.length') !== 0;
         | 
| 70 | 
            -
                }.property('dirtyProperties.length'),
         | 
| 5 | 
            +
            var slice = Array.prototype.slice;
         | 
| 71 6 |  | 
| 72 | 
            -
             | 
| 73 | 
            -
                  var serialized, _this = this;
         | 
| 7 | 
            +
            window.Resourceful = {};
         | 
| 74 8 |  | 
| 75 | 
            -
             | 
| 9 | 
            +
            Resourceful.Resource = Ember.Object.extend({
         | 
| 10 | 
            +
              resourceAdapter: null,
         | 
| 11 | 
            +
              resourceProperties: null,
         | 
| 12 | 
            +
              resourceUrl: null,
         | 
| 13 | 
            +
              serializers: null,
         | 
| 14 | 
            +
              deserializers: null,
         | 
| 76 15 |  | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
                      serialized[key] = _this.serializers[key].call(this, _this.get(key));
         | 
| 81 | 
            -
                    } else {
         | 
| 82 | 
            -
                      serialized[key] = _this.get(key);
         | 
| 83 | 
            -
                    }
         | 
| 84 | 
            -
                  });
         | 
| 85 | 
            -
             | 
| 86 | 
            -
                  if (this.resourceName) {
         | 
| 87 | 
            -
                    var s = {}; s[this.resourceName] = serialized;
         | 
| 88 | 
            -
                    return s;
         | 
| 89 | 
            -
                  } else {
         | 
| 90 | 
            -
                    return serialized;
         | 
| 91 | 
            -
                  }
         | 
| 92 | 
            -
                },
         | 
| 16 | 
            +
              isFetching: false,
         | 
| 17 | 
            +
              isFetched: false,
         | 
| 18 | 
            +
              isSaving: false,
         | 
| 93 19 |  | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 20 | 
            +
              init: function() {
         | 
| 21 | 
            +
                var _this = this;
         | 
| 96 22 |  | 
| 97 | 
            -
             | 
| 23 | 
            +
                this.persistedProperties = {};
         | 
| 24 | 
            +
                this.dirtyProperties = [];
         | 
| 98 25 |  | 
| 99 | 
            -
             | 
| 100 | 
            -
                    value = json[key];
         | 
| 26 | 
            +
                this._super();
         | 
| 101 27 |  | 
| 102 | 
            -
             | 
| 103 | 
            -
             | 
| 104 | 
            -
                     | 
| 28 | 
            +
                if (this.resourceProperties) {
         | 
| 29 | 
            +
                  this.resourceProperties.forEach(function(key) {
         | 
| 30 | 
            +
                    _this.addObserver(key, function() {
         | 
| 31 | 
            +
                      if (_this.get(key) !== _this.persistedProperties[key]) {
         | 
| 32 | 
            +
                        if (!_this.dirtyProperties.contains(key)) {
         | 
| 33 | 
            +
                          _this.dirtyProperties.pushObject(key);
         | 
| 34 | 
            +
                        }
         | 
| 35 | 
            +
                      } else {
         | 
| 36 | 
            +
                        _this.dirtyProperties.removeObject(key);
         | 
| 37 | 
            +
                      }
         | 
| 38 | 
            +
                    });
         | 
| 39 | 
            +
                  });
         | 
| 40 | 
            +
                }
         | 
| 41 | 
            +
              },
         | 
| 105 42 |  | 
| 106 | 
            -
             | 
| 107 | 
            -
             | 
| 43 | 
            +
              isNew: Ember.computed.equal('id', undefined),
         | 
| 44 | 
            +
              
         | 
| 45 | 
            +
              isDirty: Ember.computed.bool('dirtyProperties.length'),
         | 
| 108 46 |  | 
| 109 | 
            -
             | 
| 47 | 
            +
              serialize: function() {
         | 
| 48 | 
            +
                var serialized, _this = this;
         | 
| 110 49 |  | 
| 111 | 
            -
             | 
| 50 | 
            +
                serialized = {};
         | 
| 112 51 |  | 
| 113 | 
            -
             | 
| 52 | 
            +
                this.resourceProperties.forEach(function(key) {
         | 
| 53 | 
            +
                  var _ref;
         | 
| 54 | 
            +
                  if ((_ref = _this.serializers) != null ? _ref[key] : void 0) {
         | 
| 55 | 
            +
                    serialized[key] = _this.serializers[key].call(this, _this.get(key));
         | 
| 56 | 
            +
                  } else {
         | 
| 57 | 
            +
                    serialized[key] = _this.get(key);
         | 
| 58 | 
            +
                  }
         | 
| 59 | 
            +
                });
         | 
| 114 60 |  | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 61 | 
            +
                if (this.resourceName) {
         | 
| 62 | 
            +
                  var s = {}; s[this.resourceName] = serialized;
         | 
| 63 | 
            +
                  return s;
         | 
| 64 | 
            +
                } else {
         | 
| 65 | 
            +
                  return serialized;
         | 
| 66 | 
            +
                }
         | 
| 67 | 
            +
              },
         | 
| 117 68 |  | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
| 69 | 
            +
              deserialize: function(json) {
         | 
| 70 | 
            +
                var key, value, _ref;
         | 
| 120 71 |  | 
| 121 | 
            -
             | 
| 72 | 
            +
                Ember.beginPropertyChanges(this);
         | 
| 122 73 |  | 
| 123 | 
            -
             | 
| 124 | 
            -
             | 
| 125 | 
            -
                  }
         | 
| 74 | 
            +
                for (key in json) {
         | 
| 75 | 
            +
                  value = json[key];
         | 
| 126 76 |  | 
| 127 | 
            -
                  if ( | 
| 128 | 
            -
                     | 
| 77 | 
            +
                  if ((_ref = this.deserializers) != null ? _ref[key] : void 0) {
         | 
| 78 | 
            +
                    value = this.deserializers[key].call(this, value);
         | 
| 129 79 | 
             
                  }
         | 
| 130 80 |  | 
| 131 | 
            -
                   | 
| 132 | 
            -
             | 
| 133 | 
            -
                      _this.deserialize(data);
         | 
| 134 | 
            -
                      _this._updatePersistedProperties();
         | 
| 81 | 
            +
                  this.set(key, value);
         | 
| 82 | 
            +
                }
         | 
| 135 83 |  | 
| 136 | 
            -
             | 
| 137 | 
            -
                      _this.set('isFetched', true);
         | 
| 138 | 
            -
                    });
         | 
| 139 | 
            -
                },
         | 
| 84 | 
            +
                this.set('isFetched', true);
         | 
| 140 85 |  | 
| 141 | 
            -
                 | 
| 142 | 
            -
                  var success, method, _this = this;
         | 
| 86 | 
            +
                Ember.endPropertyChanges(this);
         | 
| 143 87 |  | 
| 144 | 
            -
             | 
| 88 | 
            +
                this._updatePersistedProperties();
         | 
| 145 89 |  | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 148 | 
            -
                  }
         | 
| 90 | 
            +
                return this;
         | 
| 91 | 
            +
              },
         | 
| 149 92 |  | 
| 150 | 
            -
             | 
| 151 | 
            -
             | 
| 152 | 
            -
                  }
         | 
| 93 | 
            +
              fetch: function(options) {
         | 
| 94 | 
            +
                var _this = this;
         | 
| 153 95 |  | 
| 154 | 
            -
             | 
| 155 | 
            -
                    options.data = this.serialize();
         | 
| 156 | 
            -
                  }
         | 
| 96 | 
            +
                this.set('isFetching', true);
         | 
| 157 97 |  | 
| 158 | 
            -
             | 
| 98 | 
            +
                if (!options) {
         | 
| 99 | 
            +
                  options = {};
         | 
| 100 | 
            +
                }
         | 
| 159 101 |  | 
| 160 | 
            -
             | 
| 161 | 
            -
             | 
| 162 | 
            -
             | 
| 163 | 
            -
                      _this._updatePersistedProperties();
         | 
| 102 | 
            +
                if (!options.url) {
         | 
| 103 | 
            +
                  options.url = this._resourceUrl();
         | 
| 104 | 
            +
                }
         | 
| 164 105 |  | 
| 165 | 
            -
             | 
| 166 | 
            -
             | 
| 167 | 
            -
                     | 
| 168 | 
            -
             | 
| 106 | 
            +
                return this.resourceAdapter.request('read', options)
         | 
| 107 | 
            +
                  .done(function(data, textStatus, jqXHR) {
         | 
| 108 | 
            +
                    _this.deserialize(data);
         | 
| 109 | 
            +
                    _this._updatePersistedProperties();
         | 
| 169 110 |  | 
| 170 | 
            -
             | 
| 171 | 
            -
                   | 
| 172 | 
            -
             | 
| 173 | 
            -
                  }
         | 
| 111 | 
            +
                    _this.set('isFetching', false);
         | 
| 112 | 
            +
                  });
         | 
| 113 | 
            +
              },
         | 
| 174 114 |  | 
| 175 | 
            -
             | 
| 176 | 
            -
             | 
| 177 | 
            -
                  }
         | 
| 115 | 
            +
              save: function(options) {
         | 
| 116 | 
            +
                var success, method, _this = this;
         | 
| 178 117 |  | 
| 179 | 
            -
             | 
| 180 | 
            -
                },
         | 
| 118 | 
            +
                this.set('isSaving', true);
         | 
| 181 119 |  | 
| 182 | 
            -
                 | 
| 183 | 
            -
                   | 
| 184 | 
            -
             | 
| 185 | 
            -
                },
         | 
| 120 | 
            +
                if (!options) {
         | 
| 121 | 
            +
                  options = {};
         | 
| 122 | 
            +
                }
         | 
| 186 123 |  | 
| 187 | 
            -
                 | 
| 188 | 
            -
                   | 
| 124 | 
            +
                if (!options.url) {
         | 
| 125 | 
            +
                  options.url = this._resourceUrl();
         | 
| 126 | 
            +
                }
         | 
| 189 127 |  | 
| 190 | 
            -
             | 
| 128 | 
            +
                if (!options.data) {
         | 
| 129 | 
            +
                  options.data = this.serialize();
         | 
| 130 | 
            +
                }
         | 
| 191 131 |  | 
| 192 | 
            -
             | 
| 193 | 
            -
                    _this.revert(key);
         | 
| 194 | 
            -
                  });
         | 
| 132 | 
            +
                method = this.get('isNew') ? 'create' : 'update';
         | 
| 195 133 |  | 
| 196 | 
            -
             | 
| 134 | 
            +
                return this.resourceAdapter.request(method, options)
         | 
| 135 | 
            +
                  .done(function(data, textStatus, jqXHR) {
         | 
| 136 | 
            +
                    _this.deserialize(data);
         | 
| 137 | 
            +
                    _this._updatePersistedProperties();
         | 
| 197 138 |  | 
| 198 | 
            -
             | 
| 199 | 
            -
             | 
| 139 | 
            +
                    _this.set('isSaving', false);
         | 
| 140 | 
            +
                  });
         | 
| 141 | 
            +
              },
         | 
| 200 142 |  | 
| 201 | 
            -
             | 
| 202 | 
            -
             | 
| 203 | 
            -
             | 
| 143 | 
            +
              destroy: function(options) {
         | 
| 144 | 
            +
                if (!options) {
         | 
| 145 | 
            +
                  options = {};
         | 
| 146 | 
            +
                }
         | 
| 204 147 |  | 
| 205 | 
            -
             | 
| 148 | 
            +
                if (!options.url) {
         | 
| 149 | 
            +
                  options.url = this._resourceUrl();
         | 
| 150 | 
            +
                }
         | 
| 206 151 |  | 
| 207 | 
            -
             | 
| 208 | 
            -
             | 
| 209 | 
            -
                    });
         | 
| 152 | 
            +
                return this.resourceAdapter.request('delete', options);
         | 
| 153 | 
            +
              },
         | 
| 210 154 |  | 
| 211 | 
            -
             | 
| 155 | 
            +
              revert: function(key) {
         | 
| 156 | 
            +
                this.set(key, this.persistedProperties[key]);
         | 
| 157 | 
            +
                this.dirtyProperties.removeObject(key);
         | 
| 158 | 
            +
              },
         | 
| 212 159 |  | 
| 213 | 
            -
             | 
| 214 | 
            -
             | 
| 215 | 
            -
                },
         | 
| 160 | 
            +
              revertAll: function() {
         | 
| 161 | 
            +
                var _this = this;
         | 
| 216 162 |  | 
| 217 | 
            -
                 | 
| 218 | 
            -
             | 
| 163 | 
            +
                Ember.beginPropertyChanges(this);
         | 
| 164 | 
            +
                
         | 
| 165 | 
            +
                this.dirtyProperties.forEach(function(key) {
         | 
| 166 | 
            +
                  _this.set(key, _this.persistedProperties[key]);
         | 
| 167 | 
            +
                });
         | 
| 219 168 |  | 
| 220 | 
            -
             | 
| 221 | 
            -
                    url += '/' + this.get('id');
         | 
| 222 | 
            -
                  }
         | 
| 169 | 
            +
                this.dirtyProperties.clear();
         | 
| 223 170 |  | 
| 224 | 
            -
             | 
| 225 | 
            -
             | 
| 226 | 
            -
              });
         | 
| 171 | 
            +
                Ember.endPropertyChanges(this);
         | 
| 172 | 
            +
              },
         | 
| 227 173 |  | 
| 228 | 
            -
               | 
| 229 | 
            -
                 | 
| 230 | 
            -
                   | 
| 231 | 
            -
                    return Ember.get(this.resourceCollectionPath).findById(id);
         | 
| 232 | 
            -
                  } else {
         | 
| 233 | 
            -
                    throw new Error('You cannot use `find()` without specifying a `resourceCollectionPath` on the Resource\'s prototype!');
         | 
| 234 | 
            -
                  }
         | 
| 235 | 
            -
                },
         | 
| 174 | 
            +
              _updatePersistedProperties: function() {
         | 
| 175 | 
            +
                if (Array.isArray(this.resourceProperties)) {
         | 
| 176 | 
            +
                  var persisted, _this = this;
         | 
| 236 177 |  | 
| 237 | 
            -
             | 
| 238 | 
            -
                  var collection;
         | 
| 178 | 
            +
                  persisted = {};
         | 
| 239 179 |  | 
| 240 | 
            -
                   | 
| 241 | 
            -
                     | 
| 180 | 
            +
                  this.resourceProperties.forEach(function(key) {
         | 
| 181 | 
            +
                    persisted[key] = _this.get(key);
         | 
| 182 | 
            +
                  });
         | 
| 242 183 |  | 
| 243 | 
            -
             | 
| 244 | 
            -
                      collection.fetchAll();
         | 
| 245 | 
            -
                    }
         | 
| 184 | 
            +
                  this.set('persistedProperties', persisted);
         | 
| 246 185 |  | 
| 247 | 
            -
             | 
| 248 | 
            -
                  } else {
         | 
| 249 | 
            -
                    throw new Error('You cannot use `all()` without specifying a `resourceCollectionPath` on the Resource\'s prototype!');
         | 
| 250 | 
            -
                  }
         | 
| 186 | 
            +
                  this.dirtyProperties.clear();
         | 
| 251 187 | 
             
                }
         | 
| 252 | 
            -
              } | 
| 188 | 
            +
              },
         | 
| 253 189 |  | 
| 254 | 
            -
               | 
| 255 | 
            -
                 | 
| 256 | 
            -
                resourceAdapter: null,
         | 
| 190 | 
            +
              _resourceUrl: function() {
         | 
| 191 | 
            +
                var url = this.resourceAdapter.namespace + this.constructor.resourceUrl;
         | 
| 257 192 |  | 
| 258 | 
            -
                 | 
| 259 | 
            -
             | 
| 260 | 
            -
             | 
| 261 | 
            -
                init: function() {
         | 
| 262 | 
            -
                  this._super();
         | 
| 263 | 
            -
             | 
| 264 | 
            -
                  if (!this.get('content')) {
         | 
| 265 | 
            -
                    this.set('content', []);
         | 
| 266 | 
            -
                  }
         | 
| 267 | 
            -
                },
         | 
| 193 | 
            +
                if (!this.get('isNew')) {
         | 
| 194 | 
            +
                  url += '/' + this.get('id');
         | 
| 195 | 
            +
                }
         | 
| 268 196 |  | 
| 269 | 
            -
                 | 
| 270 | 
            -
             | 
| 197 | 
            +
                return url;
         | 
| 198 | 
            +
              }
         | 
| 199 | 
            +
            });
         | 
| 271 200 |  | 
| 272 | 
            -
             | 
| 201 | 
            +
            Resourceful.Resource.reopenClass({
         | 
| 202 | 
            +
              find: function(id) {
         | 
| 203 | 
            +
                if (this.resourceCollectionPath) {
         | 
| 204 | 
            +
                  return Ember.get(this.resourceCollectionPath).findById(id);
         | 
| 205 | 
            +
                } else {
         | 
| 206 | 
            +
                  throw new Error('You cannot use `find()` without specifying a `resourceCollectionPath` on the Resource\'s prototype!');
         | 
| 207 | 
            +
                }
         | 
| 208 | 
            +
              },
         | 
| 273 209 |  | 
| 274 | 
            -
             | 
| 275 | 
            -
             | 
| 210 | 
            +
              all: function() {
         | 
| 211 | 
            +
                var collection;
         | 
| 276 212 |  | 
| 277 | 
            -
             | 
| 213 | 
            +
                if (this.resourceCollectionPath) {
         | 
| 214 | 
            +
                  collection = Ember.get(this.resourceCollectionPath);
         | 
| 278 215 |  | 
| 279 | 
            -
             | 
| 216 | 
            +
                  if (!collection.get('isFetched')) {
         | 
| 217 | 
            +
                    collection.fetchAll();
         | 
| 280 218 | 
             
                  }
         | 
| 281 219 |  | 
| 282 | 
            -
                  return  | 
| 283 | 
            -
                } | 
| 220 | 
            +
                  return collection.get('content');
         | 
| 221 | 
            +
                } else {
         | 
| 222 | 
            +
                  throw new Error('You cannot use `all()` without specifying a `resourceCollectionPath` on the Resource\'s prototype!');
         | 
| 223 | 
            +
                }
         | 
| 224 | 
            +
              }
         | 
| 225 | 
            +
            });
         | 
| 226 | 
            +
             | 
| 227 | 
            +
            Resourceful.ResourceCollection = Ember.ArrayProxy.extend({
         | 
| 228 | 
            +
              resourceClass: null,
         | 
| 229 | 
            +
              resourceAdapter: null,
         | 
| 230 | 
            +
             | 
| 231 | 
            +
              isFetching: false,
         | 
| 232 | 
            +
              isFetched: false,
         | 
| 233 | 
            +
             | 
| 234 | 
            +
              init: function() {
         | 
| 235 | 
            +
                var _this = this;
         | 
| 236 | 
            +
                
         | 
| 237 | 
            +
                this._super();
         | 
| 238 | 
            +
                
         | 
| 239 | 
            +
                this._resourceIndex = {};
         | 
| 240 | 
            +
                
         | 
| 241 | 
            +
                if (!this.get('content')) {
         | 
| 242 | 
            +
                  this.set('content', []);
         | 
| 243 | 
            +
                }
         | 
| 244 | 
            +
                
         | 
| 245 | 
            +
                this.addArrayObserver(Ember.Object.create({
         | 
| 246 | 
            +
                  arrayWillChange: function(observedObj, start, removeCount, addCount) {
         | 
| 247 | 
            +
                    var removed;
         | 
| 248 | 
            +
                  
         | 
| 249 | 
            +
                    if (removeCount > 0) {
         | 
| 250 | 
            +
                      observedObj.slice(start, start + removeCount).forEach(function(resource) {
         | 
| 251 | 
            +
                        if (_this._resourceIndex[resource.id]) {
         | 
| 252 | 
            +
                          delete _this._resourceIndex[resource.id];
         | 
| 253 | 
            +
                        }
         | 
| 254 | 
            +
                      });
         | 
| 255 | 
            +
                    }
         | 
| 256 | 
            +
                  },
         | 
| 257 | 
            +
                  arrayDidChange: function(observedObj, start, removeCount, addCount) {
         | 
| 258 | 
            +
                    var added, filtered;
         | 
| 259 | 
            +
                  
         | 
| 260 | 
            +
                    if (addCount > 0) {
         | 
| 261 | 
            +
                      observedObj.slice(start, start + addCount).forEach(function(resource) {
         | 
| 262 | 
            +
                        _this._resourceIndex[resource.id] = resource;
         | 
| 263 | 
            +
                      });
         | 
| 264 | 
            +
                    }
         | 
| 265 | 
            +
                  }
         | 
| 266 | 
            +
                }));
         | 
| 267 | 
            +
              },
         | 
| 284 268 |  | 
| 285 | 
            -
             | 
| 286 | 
            -
             | 
| 269 | 
            +
              findById: function(id) {
         | 
| 270 | 
            +
                var resource;
         | 
| 287 271 |  | 
| 288 | 
            -
             | 
| 289 | 
            -
                    options = {};
         | 
| 290 | 
            -
                  }
         | 
| 272 | 
            +
                resource = this._resourceIndex[id];
         | 
| 291 273 |  | 
| 274 | 
            +
                if (!resource) {
         | 
| 292 275 | 
             
                  resource = this.resourceClass.create({ id: id });
         | 
| 293 276 |  | 
| 294 | 
            -
                   | 
| 295 | 
            -
                    .done(function() {
         | 
| 296 | 
            -
                      _this.pushObject(resource);
         | 
| 297 | 
            -
                    });
         | 
| 298 | 
            -
                },
         | 
| 299 | 
            -
             | 
| 300 | 
            -
                fetchAll: function(options) {
         | 
| 301 | 
            -
                  var success,
         | 
| 302 | 
            -
                    _this = this;
         | 
| 277 | 
            +
                  resource.fetch();
         | 
| 303 278 |  | 
| 304 | 
            -
                  this. | 
| 279 | 
            +
                  this.pushObject(resource);
         | 
| 280 | 
            +
                }
         | 
| 305 281 |  | 
| 306 | 
            -
             | 
| 307 | 
            -
             | 
| 308 | 
            -
                  }
         | 
| 282 | 
            +
                return resource;
         | 
| 283 | 
            +
              },
         | 
| 309 284 |  | 
| 310 | 
            -
             | 
| 311 | 
            -
             | 
| 312 | 
            -
                  }
         | 
| 285 | 
            +
              fetch: function(id, options) {
         | 
| 286 | 
            +
                var resource, _this = this;
         | 
| 313 287 |  | 
| 314 | 
            -
             | 
| 315 | 
            -
             | 
| 316 | 
            -
             | 
| 317 | 
            -
                      _this.loadAll(data);
         | 
| 318 | 
            -
                      _this.set('isFetching', false);
         | 
| 319 | 
            -
                      _this.set('isFetched', true);
         | 
| 320 | 
            -
                    });
         | 
| 321 | 
            -
                },
         | 
| 288 | 
            +
                if (!options) {
         | 
| 289 | 
            +
                  options = {};
         | 
| 290 | 
            +
                }
         | 
| 322 291 |  | 
| 323 | 
            -
                 | 
| 324 | 
            -
                  var _this = this;
         | 
| 292 | 
            +
                resource = this.resourceClass.create({ id: id });
         | 
| 325 293 |  | 
| 326 | 
            -
             | 
| 327 | 
            -
             | 
| 294 | 
            +
                return resource.fetch(options)
         | 
| 295 | 
            +
                  .done(function() {
         | 
| 296 | 
            +
                    _this.pushObject(resource);
         | 
| 328 297 | 
             
                  });
         | 
| 329 | 
            -
             | 
| 298 | 
            +
              },
         | 
| 330 299 |  | 
| 331 | 
            -
             | 
| 332 | 
            -
             | 
| 300 | 
            +
              fetchAll: function(options) {
         | 
| 301 | 
            +
                var success,
         | 
| 302 | 
            +
                  _this = this;
         | 
| 333 303 |  | 
| 334 | 
            -
             | 
| 304 | 
            +
                this.set('isFetching', true);
         | 
| 335 305 |  | 
| 336 | 
            -
             | 
| 337 | 
            -
             | 
| 338 | 
            -
             | 
| 339 | 
            -
                  }
         | 
| 340 | 
            -
             | 
| 341 | 
            -
                  resource.deserialize(json);
         | 
| 342 | 
            -
             | 
| 343 | 
            -
                  resource._updatePersistedProperties();
         | 
| 344 | 
            -
                },
         | 
| 306 | 
            +
                if (!options) {
         | 
| 307 | 
            +
                  options = {};
         | 
| 308 | 
            +
                }
         | 
| 345 309 |  | 
| 346 | 
            -
                 | 
| 347 | 
            -
                   | 
| 310 | 
            +
                if (!options.url) {
         | 
| 311 | 
            +
                  options.url = this._resourceUrl();
         | 
| 348 312 | 
             
                }
         | 
| 349 | 
            -
              });
         | 
| 350 313 |  | 
| 351 | 
            -
             | 
| 352 | 
            -
             | 
| 314 | 
            +
                return this.resourceAdapter.request('read', options)
         | 
| 315 | 
            +
                  .done(function(data, textStatus, jqXHR) {
         | 
| 316 | 
            +
                    _this.content.clear();
         | 
| 317 | 
            +
                    _this._resourceIndex = {};
         | 
| 318 | 
            +
                    _this.loadAll(data);
         | 
| 319 | 
            +
                    _this.set('isFetching', false);
         | 
| 320 | 
            +
                    _this.set('isFetched', true);
         | 
| 321 | 
            +
                  });
         | 
| 322 | 
            +
              },
         | 
| 323 | 
            +
             | 
| 324 | 
            +
              loadAll: function(json) {
         | 
| 325 | 
            +
                var _this = this;
         | 
| 353 326 |  | 
| 354 | 
            -
                 | 
| 355 | 
            -
                   | 
| 327 | 
            +
                json.forEach(function(j) {
         | 
| 328 | 
            +
                  _this.load(j);
         | 
| 329 | 
            +
                });
         | 
| 330 | 
            +
              },
         | 
| 356 331 |  | 
| 357 | 
            -
             | 
| 358 | 
            -
             | 
| 359 | 
            -
                    'update': 'PUT',
         | 
| 360 | 
            -
                    'read': 'GET',
         | 
| 361 | 
            -
                    'delete': 'DELETE'
         | 
| 362 | 
            -
                  };
         | 
| 332 | 
            +
              load: function(json) {
         | 
| 333 | 
            +
                var resource;
         | 
| 363 334 |  | 
| 364 | 
            -
             | 
| 335 | 
            +
                resource = this._resourceIndex[id];
         | 
| 365 336 |  | 
| 366 | 
            -
             | 
| 367 | 
            -
             | 
| 368 | 
            -
                   | 
| 337 | 
            +
                if (!resource) {
         | 
| 338 | 
            +
                  resource = this.resourceClass.create();
         | 
| 339 | 
            +
                  this.pushObject(resource);
         | 
| 340 | 
            +
                }
         | 
| 369 341 |  | 
| 370 | 
            -
             | 
| 371 | 
            -
                    deferred.resolve(_this.prepareResponse(data), textStatus, jqXHR);
         | 
| 372 | 
            -
                  };
         | 
| 342 | 
            +
                resource.deserialize(json);
         | 
| 373 343 |  | 
| 374 | 
            -
             | 
| 375 | 
            -
             | 
| 376 | 
            -
             | 
| 344 | 
            +
                resource._updatePersistedProperties();
         | 
| 345 | 
            +
              },
         | 
| 346 | 
            +
              
         | 
| 347 | 
            +
              _resourceUrl: function() {
         | 
| 348 | 
            +
                return this.resourceAdapter.namespace + this.resourceClass.resourceUrl;
         | 
| 349 | 
            +
              }
         | 
| 350 | 
            +
            });
         | 
| 377 351 |  | 
| 378 | 
            -
             | 
| 379 | 
            -
             | 
| 380 | 
            -
                    type: crud[method]
         | 
| 381 | 
            -
                  }, options));
         | 
| 352 | 
            +
            Resourceful.ResourceAdapter = Ember.Object.extend({
         | 
| 353 | 
            +
              namespace: '',
         | 
| 382 354 |  | 
| 383 | 
            -
             | 
| 355 | 
            +
              request: function(method, options) {
         | 
| 356 | 
            +
                var crud, deferred, jqXHR, _this = this;
         | 
| 384 357 |  | 
| 385 | 
            -
             | 
| 386 | 
            -
             | 
| 387 | 
            -
                   | 
| 358 | 
            +
                crud = {
         | 
| 359 | 
            +
                  'create': 'POST',
         | 
| 360 | 
            +
                  'update': 'PUT',
         | 
| 361 | 
            +
                  'read': 'GET',
         | 
| 362 | 
            +
                  'delete': 'DELETE'
         | 
| 363 | 
            +
                };
         | 
| 388 364 |  | 
| 389 | 
            -
             | 
| 390 | 
            -
                },
         | 
| 365 | 
            +
                deferred = $.Deferred();
         | 
| 391 366 |  | 
| 392 | 
            -
                 | 
| 393 | 
            -
                   | 
| 394 | 
            -
                } | 
| 367 | 
            +
                if (!options) {
         | 
| 368 | 
            +
                  options = {};
         | 
| 369 | 
            +
                }
         | 
| 395 370 |  | 
| 396 | 
            -
                 | 
| 397 | 
            -
                   | 
| 371 | 
            +
                options.success = function(data, textStatus, jqXHR) {
         | 
| 372 | 
            +
                  deferred.resolve(_this.prepareResponse(data), textStatus, jqXHR);
         | 
| 373 | 
            +
                };
         | 
| 374 | 
            +
             | 
| 375 | 
            +
                options.error = function(jqXHR, textStatus, errorThrown) {
         | 
| 376 | 
            +
                  deferred.reject(jqXHR, textStatus, errorThrown);
         | 
| 377 | 
            +
                };
         | 
| 378 | 
            +
             | 
| 379 | 
            +
                options = this.prepareRequest(jQuery.extend({
         | 
| 380 | 
            +
                  dataType: 'json',
         | 
| 381 | 
            +
                  type: crud[method]
         | 
| 382 | 
            +
                }, options));
         | 
| 383 | 
            +
             | 
| 384 | 
            +
                jqXHR = $.ajax(options);
         | 
| 385 | 
            +
             | 
| 386 | 
            +
                ['abort'].forEach(function(method) {
         | 
| 387 | 
            +
                  deferred[method] = jqXHR[method];
         | 
| 388 | 
            +
                });
         | 
| 389 | 
            +
             | 
| 390 | 
            +
                return deferred;
         | 
| 391 | 
            +
              },
         | 
| 392 | 
            +
              
         | 
| 393 | 
            +
              buildURI: function(parts) {
         | 
| 394 | 
            +
                if (arguments.length > 1) {
         | 
| 395 | 
            +
                  parts = slice.call(arguments, 0)
         | 
| 396 | 
            +
                } else if (typeof parts === 'string') {
         | 
| 397 | 
            +
                  parts = [parts];
         | 
| 398 398 | 
             
                }
         | 
| 399 | 
            -
             | 
| 399 | 
            +
                
         | 
| 400 | 
            +
                return encodeURI((this.namespace + '/' + parts.join('/')).replace(/\/+/g, '/'));
         | 
| 401 | 
            +
              },
         | 
| 402 | 
            +
             | 
| 403 | 
            +
              prepareRequest: function(options) {
         | 
| 404 | 
            +
                return options;
         | 
| 405 | 
            +
              },
         | 
| 406 | 
            +
             | 
| 407 | 
            +
              prepareResponse: function(json) {
         | 
| 408 | 
            +
                return json;
         | 
| 409 | 
            +
              }
         | 
| 410 | 
            +
            });
         | 
| 400 411 |  | 
| 401 412 | 
             
            }).call(this);
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: ember-resourceful-rails
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Dan Martens
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2013- | 
| 11 | 
            +
            date: 2013-07-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         |