Class: ActionDispatch::Routing::Mapper
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::Mapper
- Defined in:
- lib/rest_framework/routers.rb
Instance Method Summary collapse
-
#rest_resource(*names, **kwargs, &block) ⇒ Object
Public interface for creating singular RESTful resource routes.
-
#rest_resources(*names, **kwargs, &block) ⇒ Object
Public interface for creating plural RESTful resource routes.
-
#rest_root(name = nil, **kwargs, &block) ⇒ Object
Route a controller’s ‘#root` to ’/‘ in the current scope/namespace, along with other actions.
-
#rest_route(name = nil, **kwargs, &block) ⇒ Object
Route a controller without the default resourceful paths.
Instance Method Details
#rest_resource(*names, **kwargs, &block) ⇒ Object
Public interface for creating singular RESTful resource routes.
103 104 105 106 107 |
# File 'lib/rest_framework/routers.rb', line 103 def rest_resource(*names, **kwargs, &block) names.each do |n| self._rest_resources(true, n, **kwargs, &block) end end |
#rest_resources(*names, **kwargs, &block) ⇒ Object
Public interface for creating plural RESTful resource routes.
110 111 112 113 114 |
# File 'lib/rest_framework/routers.rb', line 110 def rest_resources(*names, **kwargs, &block) names.each do |n| self._rest_resources(false, n, **kwargs, &block) end end |
#rest_root(name = nil, **kwargs, &block) ⇒ Object
Route a controller’s ‘#root` to ’/‘ in the current scope/namespace, along with other actions.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/rest_framework/routers.rb', line 142 def rest_root(name=nil, **kwargs, &block) # By default, use RootController#root. root_action = kwargs.delete(:action) || :root controller = kwargs.delete(:controller) || name || :root # Remove path if name is nil (routing to the root of current namespace). unless name kwargs[:path] = "" end return rest_route(controller, route_root_to: root_action, **kwargs) do yield if block_given? end end |
#rest_route(name = nil, **kwargs, &block) ⇒ Object
Route a controller without the default resourceful paths.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/rest_framework/routers.rb', line 117 def rest_route(name=nil, **kwargs, &block) controller = kwargs.delete(:controller) || name route_root_to = kwargs.delete(:route_root_to) if controller.is_a?(Class) controller_class = controller else controller_class = self._get_controller_class(controller, pluralize: false) end # Set controller if it's not explicitly set. kwargs[:controller] = name unless kwargs[:controller] # Route actions using the resourceful router, but skip all builtin actions. actions = RESTFramework::Utils.parse_extra_actions(controller_class.extra_actions) public_send(:resource, name, only: [], **kwargs) do # Route a root for this resource. if route_root_to get("", action: route_root_to) end self._route_extra_actions(actions, &block) end end |