1# frozen_string_literal: true
2
3module Gitlab
4  module TemplateParser
5    # A class for tracking state when evaluating a template
6    class EvalState
7      MAX_LOOPS = 4
8
9      def initialize
10        @loops = 0
11      end
12
13      def enter_loop
14        if @loops == MAX_LOOPS
15          raise Error, "You can only nest up to #{MAX_LOOPS} loops"
16        end
17
18        @loops += 1
19        retval = yield
20        @loops -= 1
21
22        retval
23      end
24    end
25  end
26end
27