Class: ActionDispatch::Routing::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/mapper.rb

Instance Method Summary collapse

Instance Method Details

#context(name, &blk) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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) ⇒ Object



3
4
5
6
7
8
9
10
11
# 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