summaryrefslogtreecommitdiff
path: root/lib/gitlab/serializer/ci/variables.rb
blob: c059c454eac9957bf3a64c79282190c70e1b94d4 (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
27
module Gitlab
  module Serializer
    module Ci
      # This serializer could make sure our YAML variables' keys and values
      # are always strings. This is more for legacy build data because
      # from now on we convert them into strings before saving to database.
      module Variables
        extend self

        def load(string)
          return unless string

          object = YAML.safe_load(string, [Symbol])

          object.map do |variable|
            variable[:key] = variable[:key].to_s
            variable
          end
        end

        def dump(object)
          YAML.dump(object)
        end
      end
    end
  end
end