Sha256: 131d0f6708a31c80b31af83b42c6e9704c5ad0e676d353875a9235839f3c6472

Contents?: true

Size: 645 Bytes

Versions: 1

Compression:

Stored size: 645 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)
      name = "#{name}_context".classify.constantize unless name.is_a?(Class)
      ctx = name.new
      path = ":#{ctx.key}"
      path = "(#{path})" unless ctx.required?

      constraints = lambda do |req|
        (req.env['contexts'] ||= {})[ctx.key] = ctx
        ctx.matches_constraints?(req)
      end

      scope(path, constraints: constraints, &blk)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
contexts-0.1.1 lib/mapper.rb