Class: Gitlab::Ci::Config::Interpolation::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/config/interpolation/context.rb

Overview

Interpolation::Context is a class that represents the data that can be used when performing string interpolation on a CI configuration.

Constant Summary collapse

ContextTooComplexError =
Class.new(StandardError)
NotSymbolizedContextError =
Class.new(StandardError)
MAX_DEPTH =
3

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Context

Returns a new instance of Context.



17
18
19
20
21
# File 'lib/gitlab/ci/config/interpolation/context.rb', line 17

def initialize(hash)
  @context = hash

  raise ContextTooComplexError if depth > MAX_DEPTH
end

Instance Method Details

#depthObject



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

def depth
  deep_depth(@context)
end

#errorsObject

This method is here because ‘Context` will be responsible for validating specs, inputs and defaults.



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

def errors
  []
end

#fetch(field) ⇒ Object



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

def fetch(field)
  @context.fetch(field)
end

#key?(name) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/gitlab/ci/config/interpolation/context.rb', line 42

def key?(name)
  @context.key?(name)
end

#to_hObject



46
47
48
# File 'lib/gitlab/ci/config/interpolation/context.rb', line 46

def to_h
  @context.to_h
end

#valid?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/gitlab/ci/config/interpolation/context.rb', line 23

def valid?
  errors.none?
end