lib/ridley/resource.rb in ridley-0.7.0.rc1 vs lib/ridley/resource.rb in ridley-0.7.0.rc3

- old
+ new

@@ -65,11 +65,11 @@ # @param [String, #chef_id] object # # @return [nil, Object] def find(client, object) find!(client, object) - rescue Errors::HTTPNotFound + rescue Errors::ResourceNotFound nil end # @param [Ridley::Client] client # @param [String, #chef_id] object @@ -79,20 +79,22 @@ # # @return [Object] def find!(client, object) chef_id = object.respond_to?(:chef_id) ? object.chef_id : object new(client, client.connection.get("#{self.resource_path}/#{chef_id}").body) + rescue Errors::HTTPNotFound => ex + raise Errors::ResourceNotFound, ex end # @param [Ridley::Client] client # @param [#to_hash] object # # @return [Object] def create(client, object) resource = new(client, object.to_hash) new_attributes = client.connection.post(self.resource_path, resource.to_json).body - resource.attributes = resource.attributes.deep_merge(new_attributes) + resource.mass_assign(resource._attributes_.deep_merge(new_attributes)) resource end # @param [Ridley::Client] client # @param [String, #chef_id] object @@ -145,11 +147,11 @@ # # @return [Boolean] def save raise Errors::InvalidResource.new(self.errors) unless valid? - mass_assign(self.class.create(client, self).attributes) + mass_assign(self.class.create(client, self)._attributes_) true rescue Errors::HTTPConflict self.update true end @@ -162,28 +164,28 @@ # # @return [Boolean] def update raise Errors::InvalidResource.new(self.errors) unless valid? - mass_assign(self.class.update(client, self).attributes) + mass_assign(self.class.update(client, self)._attributes_) true end # Reload the attributes of the instantiated resource # # @return [Object] def reload - mass_assign(self.class.find(client, self).attributes) + mass_assign(self.class.find(client, self)._attributes_) self end # @return [String] def chef_id get_attribute(self.class.chef_id) end def to_s - self.attributes + "#{self.chef_id}: #{self._attributes_}" end # @param [Object] other # # @return [Boolean]