Class: Gitlab::Ci::Config::Yaml::Tags::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/config/yaml/tags/resolver.rb

Overview

This class is the entry point for transforming custom YAML tags back into primitive objects. Usage: `Resolver.new(a_hash_including_custom_tag_objects).to_hash`

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Resolver

Returns a new instance of Resolver.


15
16
17
# File 'lib/gitlab/ci/config/yaml/tags/resolver.rb', line 15

def initialize(config)
  @config = config.deep_dup
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.


13
14
15
# File 'lib/gitlab/ci/config/yaml/tags/resolver.rb', line 13

def config
  @config
end

Instance Method Details

#deep_resolve(object) ⇒ Object


23
24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/ci/config/yaml/tags/resolver.rb', line 23

def deep_resolve(object)
  case object
  when Array
    object.map(&method(:resolve_wrapper))
  when Hash
    object.deep_transform_values(&method(:resolve_wrapper))
  else
    resolve_wrapper(object)
  end
end

#resolve_wrapper(object) ⇒ Object


34
35
36
37
38
39
40
# File 'lib/gitlab/ci/config/yaml/tags/resolver.rb', line 34

def resolve_wrapper(object)
  if object.respond_to?(:resolve)
    object.resolve(self)
  else
    object
  end
end

#to_hashObject


19
20
21
# File 'lib/gitlab/ci/config/yaml/tags/resolver.rb', line 19

def to_hash
  deep_resolve(config)
end