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



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/rest_framework/routers.rb', line 136

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

#rest_route(path = nil, skip_undefined: true, **kwargs, &block) ⇒ Object

Route a controller without the default resourceful paths.



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

def rest_route(path=nil, skip_undefined: true, **kwargs, &block)
  controller = kwargs.delete(:controller) || path
  path = path.to_s

  # route actions
  controller_class = self._get_controller_class(controller, pluralize: false)
  skip = controller_class.get_skip_actions(skip_undefined: skip_undefined)
  actions = controller_class.extra_actions || {}
  actions = actions.select { |k,v| controller_class.method_defined?(k) } if skip_undefined
  actions.reject! { |k,v| skip.include? k }
  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