summaryrefslogtreecommitdiff
path: root/lib/gitlab/config/loader/yaml.rb
blob: f34c8568b6aff7aff1db4fc2e8781338005ea772 (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