summaryrefslogtreecommitdiff
path: root/lib/gitlab/template_parser/eval_state.rb
blob: 7cf2ab21f503fba1abc0b0dbbb41fe3d3135a890 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

module Gitlab
  module TemplateParser
    # A class for tracking state when evaluating a template
    class EvalState
      MAX_LOOPS = 4

      def initialize
        @loops = 0
      end

      def enter_loop
        if @loops == MAX_LOOPS
          raise Error, "You can only nest up to #{MAX_LOOPS} loops"
        end

        @loops += 1
        retval = yield
        @loops -= 1

        retval
      end
    end
  end
end