class Grape::Namespace

A container for endpoints or other namespaces, which allows for both logical grouping of endpoints as well as sharing commonconfiguration. May also be referred to as group, segment, or resource.

Attributes

options[R]
space[R]

Public Class Methods

joined_space(settings) click to toggle source

(see ::joined_space_path)

# File lib/grape/namespace.rb, line 25
def self.joined_space(settings)
  (settings || []).map(&:space).join('/')
end
joined_space_path(settings) click to toggle source

Join the namespaces from a list of settings to create a path prefix. @param settings [Array] list of Grape::Util::InheritableSettings.

# File lib/grape/namespace.rb, line 31
def self.joined_space_path(settings)
  Rack::Mount::Utils.normalize_path(joined_space(settings))
end
new(space, options = {}) click to toggle source

@param space [String] the name of this namespace @param options [Hash] options hash @option options :requirements [Hash] param-regex pairs, all of which must

be met by a request's params for all endpoints in this namespace, or
validation will fail and return a 422.
# File lib/grape/namespace.rb, line 13
def initialize(space, options = {})
  @space = space.to_s
  @options = options
end

Public Instance Methods

requirements() click to toggle source

Retrieves the requirements from the options hash, if given. @return [Hash]

# File lib/grape/namespace.rb, line 20
def requirements
  options[:requirements] || {}
end