Method: Grape::DSL::Routing::ClassMethods#namespace
- Defined in:
- lib/grape/dsl/routing.rb
#namespace(space = nil, options = {}, &block) ⇒ Object Also known as: group, resource, resources, segment
Declare a “namespace”, which prefixes all subordinate routes with its name. Any endpoints within a namespace, or group, resource, segment, etc., will share their parent context as well as any configuration done in the namespace context.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/grape/dsl/routing.rb', line 165 def namespace(space = nil, = {}, &block) @namespace_description = nil unless instance_variable_defined?(:@namespace_description) && @namespace_description if space || block_given? within_namespace do previous_namespace_description = @namespace_description @namespace_description = (@namespace_description || {}).deep_merge(namespace_setting(:description) || {}) nest(block) do if space namespace_stackable(:namespace, Namespace.new(space, **)) end end @namespace_description = previous_namespace_description end else Namespace.joined_space_path(namespace_stackable(:namespace)) end end |