Class: RESTRack::ResourceController
- Extended by:
- ResourceRelations
- Defined in:
- lib/restrack/resource_controller.rb
Overview
All RESTRack controllers should descend from ResourceController. This class provides the methods for your controllers.
HTTP Verb: | GET | PUT | POST | DELETE
Collection URI (/widgets/): | index | replace | create | drop Element URI (/widgets/42): | show | update | add | destroy
Class Attribute Summary collapse
-
.key_type ⇒ Object
Returns the value of attribute key_type.
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#resource_request ⇒ Object
readonly
Returns the value of attribute resource_request.
Class Method Summary collapse
-
.__init(resource_request) ⇒ Object
Base initialization method for resources and storage of request input This method should not be overriden in decendent classes.
Instance Method Summary collapse
- #__init(resource_request) ⇒ Object
-
#call ⇒ Object
Call the controller’s action and return output in the proper format.
Methods included from ResourceRelations
has_defined_relationships_to, has_mapped_relationships_to, has_relationship_to, has_relationships_to, keyed_with_type, pass_through_to
Class Attribute Details
Instance Attribute Details
permalink #action ⇒ Object (readonly)
Returns the value of attribute action.
16 17 18 |
# File 'lib/restrack/resource_controller.rb', line 16 def action @action end |
permalink #id ⇒ Object (readonly)
Returns the value of attribute id.
16 17 18 |
# File 'lib/restrack/resource_controller.rb', line 16 def id @id end |
Class Method Details
permalink .__init(resource_request) ⇒ Object
Base initialization method for resources and storage of request input This method should not be overriden in decendent classes.
21 22 23 24 |
# File 'lib/restrack/resource_controller.rb', line 21 def self.__init(resource_request) __self = self.new return __self.__init(resource_request) end |
Instance Method Details
permalink #__init(resource_request) ⇒ Object
[View source]
25 26 27 28 29 30 31 32 |
# File 'lib/restrack/resource_controller.rb', line 25 def __init(resource_request) @resource_request = resource_request @request = @resource_request.request @params = @resource_request.params @post_params = @resource_request.post_params @get_params = @resource_request.get_params self end |
permalink #call ⇒ Object
Call the controller’s action and return output in the proper format.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/restrack/resource_controller.rb', line 35 def call self.determine_action args = [] args << @id unless @id.blank? unless self.respond_to?(@action.to_sym) or self.respond_to?(:method_missing) raise HTTP405MethodNotAllowed, 'Method not provided on controller.' end begin self.send(@action.to_sym, *args) rescue ArgumentError raise HTTP400BadRequest, 'Method called with the incorrect number of arguments. This is most likely due to a call to an action that accepts identifier, which was not supplied in URL.' end end |