lib/acfs/model/persistence.rb in acfs-0.14.0 vs lib/acfs/model/persistence.rb in acfs-0.15.0

- old
+ new

@@ -50,20 +50,13 @@ def save!(opts = {}) # :nodoc: #raise ::Acfs::InvalidResource errors: errors.to_a unless valid? opts[:data] = attributes unless opts[:data] - request = new? ? create_request(opts) : put_request(opts) - request.on_complete do |response| - if response.success? - update_with response.data - else - self.class.raise! response - end + operation (new? ? :create : :update), opts do |data| + update_with data end - - self.class.service.run request end module ClassMethods # Create a new resource sending given data. If resource cannot be @@ -93,17 +86,9 @@ private def update_with(data) self.attributes = data loaded! - end - - def create_request(opts = {}) - Acfs::Request.new self.class.url, method: :post, data: opts[:data] - end - - def put_request(opts = {}) - Acfs::Request.new url, method: :put, data: opts[:data] end end end end