Sha256: 0f1dfda16f6b44f64f1c012697a476469bd63383100680e21225d19cc6786416
Contents?: true
Size: 641 Bytes
Versions: 1
Compression:
Stored size: 641 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})" if 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.0 | lib/mapper.rb |