Module: RemoteResource::Querying::PersistenceMethods

Extended by:
ActiveSupport::Concern
Defined in:
lib/remote_resource/querying/persistence_methods.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#destroy(connection_options = {}) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/remote_resource/querying/persistence_methods.rb', line 34

def destroy(connection_options = {})
  id.present? || raise(RemoteResource::IdMissingError.new("`id` is missing from resource"))
  response = RemoteResource::Request.new(self, :delete, {}, connection_options.merge(id: id)).perform
  handle_response(response)
  self.destroyed = success?
  success? ? self : false
end

#save(connection_options = {}) ⇒ Object



29
30
31
32
# File 'lib/remote_resource/querying/persistence_methods.rb', line 29

def save(connection_options = {})
  create_or_update(self.attributes, connection_options)
  success? ? self : false
end

#update_attributes(attributes = {}, connection_options = {}) ⇒ Object



23
24
25
26
27
# File 'lib/remote_resource/querying/persistence_methods.rb', line 23

def update_attributes(attributes = {}, connection_options = {})
  rebuild_resource(attributes)
  create_or_update(attributes.reverse_merge(id: id), connection_options)
  success? ? self : false
end