class Rutter::Scope
Represents a scoped set.
@private
Public Class Methods
new(router, path: nil, namespace: nil, as: nil, &block)
click to toggle source
Initializes the scope.
@param router [Rutter::Builder]
Router object.
@param path [String]
Scope path prefix.
@param namespace [String, Symbol]
Scope namespace.
@param as [Symbol]
Scope name prefix.
@yield
Block is evaluated inside the created scope context.
@return [void]
@private
# File lib/rutter/scope.rb, line 27 def initialize(router, path: nil, namespace: nil, as: nil, &block) @router = router @path = path @namespace = namespace @as = as instance_eval(&block) if block_given? end
Public Instance Methods
add(verb, path, to: nil, as: nil, constraints: nil, &block)
click to toggle source
@see Rutter::Builder#add
# File lib/rutter/scope.rb, line 52 def add(verb, path, to: nil, as: nil, constraints: nil, &block) path = Naming.join(@path, path) to = Naming.join(@namespace, to) if to.is_a?(String) as = Naming.join(@as, as) if as @router.add verb, path, to: to, as: as, constraints: constraints, &block end
mount(app, at:, host: nil)
click to toggle source
# File lib/rutter/scope.rb, line 37 def mount(app, at:, host: nil) @router.mount app, at: Naming.join(@path, at), host: host end
namespace(name, &block)
click to toggle source
@see Rutter::Builder#namespace
# File lib/rutter/scope.rb, line 47 def namespace(name, &block) scope path: name, namespace: name, as: name, &block end
scope(path: nil, namespace: nil, as: nil, &block)
click to toggle source
# File lib/rutter/scope.rb, line 42 def scope(path: nil, namespace: nil, as: nil, &block) Scope.new(self, path: path, namespace: namespace, as: as, &block) end