summaryrefslogtreecommitdiff
path: root/lib/gitlab/serialize/ci/variables.rb
blob: 3a9443bfcd981e7fae080836c79a69f20b6a5f3e (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 Serialize
    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