summaryrefslogtreecommitdiff
path: root/lib/gitlab/template_parser/eval_state.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/template_parser/eval_state.rb')
-rw-r--r--lib/gitlab/template_parser/eval_state.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/gitlab/template_parser/eval_state.rb b/lib/gitlab/template_parser/eval_state.rb
new file mode 100644
index 00000000000..7cf2ab21f50
--- /dev/null
+++ b/lib/gitlab/template_parser/eval_state.rb
@@ -0,0 +1,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