1# frozen-string-literal: true
 2
 3# Build from official params_capturing plugin
 4class RodaCapture
 5	module RequestMethods
 6		def captures_hash
 7			@captures_hash ||= {}
 8		end
 9
10	private
11
12		# Add the symbol to the list of capture names if capturing
13		def _match_symbol(sym)
14			@_sym_captures << sym if @_sym_captures
15
16			super
17		end
18
19		# If all arguments are strings or symbols, turn on param capturing during
20		# the matching, but turn it back off before yielding to the block.	Add
21		# any captures to the params based on the param capture names added by
22		# the matchers.
23		def if_match(args)
24			@_sym_captures = [] if args.all? { |x| x.is_a?(Symbol) }
25
26			super do |*a|
27				if @_sym_captures
28					@_sym_captures.zip(a).each do |k, v|
29						captures_hash[k] = v
30					end
31					@_sym_captures = nil
32				end
33				yield(*a)
34			end
35		end
36	end
37end