Class: ActionDispatch::Routing::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rest_framework/routers.rb

Instance Method Summary collapse

Instance Method Details

#rest_resource(*names, **kwargs, &block) ⇒ Object

Public interface for creating singular RESTful resource routes.



101
102
103
104
105
# File 'lib/rest_framework/routers.rb', line 101

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.



108
109
110
111
112
# File 'lib/rest_framework/routers.rb', line 108

def rest_resources(*names, **kwargs, &block)
  names.each do |n|
    self._rest_resources(false, n, **kwargs, &block)
  end
end

#rest_root(path = nil, **kwargs, &block) ⇒ Object

Route a controller’s ‘#root` to ’/‘ in the current scope/namespace, along with other actions.

Parameters:

  • label (Symbol)

    the snake_case name of the controller



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/rest_framework/routers.rb', line 116

def rest_root(path=nil, **kwargs, &block)
  # by default, use RootController#root
  root_action = kwargs.delete(:action) || :root
  controller = kwargs.delete(:controller) || path || :root
  path = path.to_s

  # route the root
  get path, controller: controller, action: root_action

  # route any additional actions
  controller_class = self._get_controller_class(controller, pluralize: false)
  controller_class.extra_actions.each do |action, methods|
    methods = [methods] if methods.is_a?(Symbol) || methods.is_a?(String)
    methods.each do |m|
      public_send(m, File.join(path, action.to_s), controller: controller, action: action)
    end
    yield if block_given?
  end
end