summaryrefslogtreecommitdiff
path: root/lib/gitlab/config/loader/yaml.rb
blob: 8159f8b802664422156d4c308a43ed70774d2198 (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
# frozen_string_literal: true

module Gitlab
  module Config
    module Loader
      class Yaml
        def initialize(config)
          @config = YAML.safe_load(config, [Symbol], [], true)
        rescue Psych::Exception => e
          raise Loader::FormatError, e.message
        end

        def valid?
          @config.is_a?(Hash)
        end

        def load!
          unless valid?
            raise Loader::FormatError, 'Invalid configuration format'
          end

          @config.deep_symbolize_keys
        end
      end
    end
  end
end