Module: Forem::APIOperations::Delete
- Included in:
- Forem::AdminConcept, Organization, Page, RequestRedirect, Segment
- Defined in:
- lib/forem/api_operations/delete.rb
Overview
Adds delete as both a class method and an instance method to any
resource that includes this module.
The class method deletes by ID; the instance method deletes the receiver
using its own Forem::APIResource#resource_url. Both methods return a resource
object if the server responds with a body, otherwise they return nil
(class method) or self (instance method).
The self.included hook extends the including class with ClassMethods
so the class-level delete is available alongside the instance method.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ void
Hook called when Delete is included in a class.
Instance Method Summary collapse
-
#delete(opts = {}) ⇒ ForemObject
Delete this resource instance via the Forem API.
Class Method Details
.included(base) ⇒ void
This method returns an undefined value.
Hook called when Forem::APIOperations::Delete is included in a class.
Extends the including class with ClassMethods.
25 26 27 |
# File 'lib/forem/api_operations/delete.rb', line 25 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#delete(opts = {}) ⇒ ForemObject
Delete this resource instance via the Forem API.
Sends a DELETE request to this instance's Forem::APIResource#resource_url.
If the server responds with a non-empty body it is used to construct
a new resource instance (representing the deleted state); otherwise
self is returned.
81 82 83 84 85 |
# File 'lib/forem/api_operations/delete.rb', line 81 def delete(opts = {}) requestor = opts[:requestor] || @requestor resp = request(:delete, resource_url, {}, opts) resp.parsed_body ? self.class.construct_from(resp.parsed_body, requestor: requestor) : self end |