Sha256: 40e2953f31d9e26f6de1ad07fc57e8c1b8f06f8bdad36c63831808cc6eb76a1e

Contents?: true

Size: 672 Bytes

Versions: 1

Compression:

Stored size: 672 Bytes

Contents

module ActionDispatch::Routing
  class Mapper
    def contexts(*names, &blk)
      names.reverse.each do |name|
        blk = lambda do |blk|
          lambda { context(name, &blk) }
        end.call(blk)
      end

      blk.call
    end

    def context(name, &blk)
      ctx = Contexts.resolve(name)

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

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

        scope(path, options, &blk)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
contexts-1.1.0 lib/mapper.rb