Class: Tupplur::RESTEndpoint
- Inherits:
-
Cuba
- Object
- Cuba
- Tupplur::RESTEndpoint
- Defined in:
- lib/tupplur/rest_endpoint.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(model) ⇒ RESTEndpoint
constructor
A new instance of RESTEndpoint.
Constructor Details
#initialize(model) ⇒ RESTEndpoint
Returns a new instance of RESTEndpoint.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tupplur/rest_endpoint.rb', line 9 def initialize(model) @model = model super() do on ":id" do |document_id| # REST read document on get do begin send_json(@model.rest_read(document_id)) rescue Tupplur::Error::RESTOperationNotAllowed => e res.status = 401 end end # REST update document on put, param('data') do |client_model| begin send_json(@model.rest_update(document_id, client_model)) rescue Tupplur::Error::RESTOperationNotAllowed => e res.status = 401 end end # REST delete document on delete do begin send_json(@model.rest_delete(document_id)) rescue Tupplur::Error::RESTOperationNotAllowed => e res.status = 401 end end end # REST read whole collection on get do begin send_json(@model.rest_read) rescue Tupplur::Error::RESTOperationNotAllowed => e res.status = 401 end end # REST create document on post, param('data') do |client_fields| begin @model.rest_create(client_fields) rescue Tupplur::Error::RESTOperationNotAllowed => e res.status = 401 end end end end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/tupplur/rest_endpoint.rb', line 7 def model @model end |
Class Method Details
.define ⇒ Object
61 62 63 |
# File 'lib/tupplur/rest_endpoint.rb', line 61 def self.define raise NotImplementedError, "Use .new and run the app instead." end |