Method: Grape::DSL::Routing::ClassMethods#route_param

Defined in:
lib/grape/dsl/routing.rb

#route_param(param, options = {}, &block) ⇒ Object

Thie method allows you to quickly define a parameter route segment in your API.

Parameters:

  • param (Symbol)

    The name of the parameter you wish to declare.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • You (Regexp)

    may supply a regular expression that the declared parameter must meet.



209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/grape/dsl/routing.rb', line 209

def route_param(param, options = {}, &block)
  options = options.dup

  options[:requirements] = {
    param.to_sym => options[:requirements]
  } if options[:requirements].is_a?(Regexp)

  Grape::Validations::ParamsScope.new(api: self) do
    requires param, type: options[:type]
  end if options.key?(:type)

  namespace(":#{param}", options, &block)
end