Sha256: 92b96e18749eaf5157278b4da91472b721476271a2a3bc8b4e0b4f58b0dd5cf1
Contents?: true
Size: 1.15 KB
Versions: 3
Compression:
Stored size: 1.15 KB
Contents
module MotionResource class Base def save(&block) @new_record ? create(&block) : update(&block) end def update(&block) self.class.put(member_url, :payload => { self.class.name.underscore => attributes }) do |response, json| self.class.request_block_call(block, json.blank? ? self : self.class.instantiate(json), response) if block end end def create(&block) # weird heisenbug: Specs crash without that line :( dummy = self self.class.post(collection_url, :payload => { self.class.name.underscore => attributes }) do |response, json| self.class.request_block_call(block, json.blank? ? self : self.class.instantiate(json), response) if block end end def destroy(&block) self.class.delete(member_url) do |response, json| self.class.request_block_call(block, json.blank? ? nil : self.class.instantiate(json), response) if block end end def reload(&block) self.class.get(member_url) do |response, json| self.class.request_block_call(block, json.blank? ? nil : self.class.instantiate(json), response) if block end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
motion-resource-0.1.1 | lib/motion-resource/crud.rb |
motion-resource-0.1.0 | lib/motion-resource/crud.rb |
motion-resource-0.0.2 | lib/motion-resource/crud.rb |