Class: RubyRest::CRUDServlet
- Inherits:
-
RESTServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- RESTServlet
- RubyRest::CRUDServlet
- Defined in:
- lib/rubyrest/servlets.rb
Overview
Generic servlet, that implements the Moodisland Grape API This layer returns domain objects that can be included in atom feeds as entries.
Constant Summary
Constants inherited from RESTServlet
Constants included from Atom
Atom::ATOMSERV_TYPE, Atom::ATOM_TYPE, Atom::HTML_TYPE, Atom::MODULEID, Atom::NAMESPACES, Atom::WORKSPACE_METHOD
Constants included from Tools
Tools::ATOM_DATE_FORMAT, Tools::ERRORS
Instance Method Summary collapse
-
#create(request) ⇒ Object
Creates and saves a new object.
-
#delete(request) ⇒ Object
Deletes a single object.
-
#retrieve(request) ⇒ Object
Retrieves a list of objects.
-
#retrieve_related(request) ⇒ Object
Retrieve a list of related objects.
-
#show(request) ⇒ Object
Retrieves a single object.
-
#update(request) ⇒ Object
Retrieves, updates and saves an existing object.
Methods inherited from RESTServlet
#anonymous_access, #check_security, #credentials_create, #dashboard, #dispatch, #do_DELETE, #do_GET, #do_POST, #do_PUT, #incompatible_path, #initialize, #resolve_custom_method, #resolve_get_method, #resolve_params, #resolve_service_method
Methods included from Atom
#build_entry, #build_feed, #build_service_document, #format_response
Methods included from Tools
#error, #format_atom_date, #nvl, #parse_atom_date, #to_class, #to_gem_name, #to_module_name
Constructor Details
This class inherits a constructor from RubyRest::RESTServlet
Instance Method Details
#create(request) ⇒ Object
Creates and saves a new object. The object is then returned
181 182 183 184 185 186 |
# File 'lib/rubyrest/servlets.rb', line 181 def create( request ) clazz = to_class( @servicemodule, @model ) object = clazz.rest_create( @principal ) clazz.rest_bind( object, @body ) clazz.rest_save( object, @principal ) end |
#delete(request) ⇒ Object
Deletes a single object
215 216 217 218 |
# File 'lib/rubyrest/servlets.rb', line 215 def delete( request ) clazz = to_class( @servicemodule, @model ) clazz.rest_delete( @id, @principal ) end |
#retrieve(request) ⇒ Object
Retrieves a list of objects
190 191 192 193 |
# File 'lib/rubyrest/servlets.rb', line 190 def retrieve( request ) clazz = to_class( @servicemodule, @model ) clazz.rest_retrieve( @principal ) end |
#retrieve_related(request) ⇒ Object
Retrieve a list of related objects
197 198 199 200 201 202 |
# File 'lib/rubyrest/servlets.rb', line 197 def ( request ) clazz = to_class( @servicemodule, @model ) service_method = "rest_#{@property}" error( 500, clazz.name, service_method ) if !clazz.respond_to?( service_method ) clazz.method( service_method ).call( @id, @principal ) end |
#show(request) ⇒ Object
Retrieves a single object
206 207 208 209 210 211 |
# File 'lib/rubyrest/servlets.rb', line 206 def show( request ) clazz = to_class( @servicemodule, @model ) single = clazz.rest_single( @id, @principal ) raise error( 200, @model, @id ) if single == nil return single end |
#update(request) ⇒ Object
Retrieves, updates and saves an existing object. The object is then returned
223 224 225 226 227 228 |
# File 'lib/rubyrest/servlets.rb', line 223 def update( request ) object = show( request ) clazz = object.class clazz.rest_bind( object, @body ) clazz.rest_save( object, @principal ) end |