class ActionDispatch::Routing::Mapper

Public Instance Methods

context(name, &blk) click to toggle source
# File lib/mapper.rb, line 13
def context(name, &blk)
  ctx = Contexts.resolve(name)

  path = ":#{name}"
  path = "(#{path})" unless ctx.respond_to?(:required?) and ctx.required?

  constraints ->(req) { (req.env['contexts'] ||= {})[name] = ctx } do
    if ctx.respond_to?(:constraints)
      options = { constraints: { name => ctx.constraints } }
    end

    scope(path, options, &blk)
  end
end
contexts(*names, &blk) click to toggle source
# File lib/mapper.rb, line 3
def contexts(*names, &blk)
  names.reverse.each do |name|
    blk = lambda do |blk|
      lambda { context(name, &blk) }
    end.call(blk)
  end

  blk.call
end