Class: Gitlab::Ci::Config::Interpolation::Template

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/config/interpolation/template.rb

Constant Summary collapse

TooManyBlocksError =
Class.new(StandardError)
InvalidBlockError =
Class.new(StandardError)
MAX_BLOCKS =
10_000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, ctx) ⇒ Template

Returns a new instance of Template.



17
18
19
20
21
22
23
24
# File 'lib/gitlab/ci/config/interpolation/template.rb', line 17

def initialize(config, ctx)
  @config = Interpolation::Config.fabricate(config)
  @ctx = Interpolation::Context.fabricate(ctx)
  @errors = []
  @blocks = {}

  interpolate! if valid?
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



10
11
12
# File 'lib/gitlab/ci/config/interpolation/template.rb', line 10

def blocks
  @blocks
end

#ctxObject (readonly)

Returns the value of attribute ctx.



10
11
12
# File 'lib/gitlab/ci/config/interpolation/template.rb', line 10

def ctx
  @ctx
end

Instance Method Details

#errorsObject



30
31
32
# File 'lib/gitlab/ci/config/interpolation/template.rb', line 30

def errors
  @errors + @config.errors + @ctx.errors + @blocks.values.flat_map(&:errors)
end

#interpolatedObject



38
39
40
# File 'lib/gitlab/ci/config/interpolation/template.rb', line 38

def interpolated
  @result if valid?
end

#sizeObject



34
35
36
# File 'lib/gitlab/ci/config/interpolation/template.rb', line 34

def size
  @blocks.size
end

#valid?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/gitlab/ci/config/interpolation/template.rb', line 26

def valid?
  errors.none?
end