2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
module Gitlab
|
2018-12-23 12:14:25 +05:30
|
|
|
module Config
|
|
|
|
module Loader
|
|
|
|
class Yaml
|
2016-06-16 23:09:34 +05:30
|
|
|
def initialize(config)
|
|
|
|
@config = YAML.safe_load(config, [Symbol], [], true)
|
2018-03-17 18:26:18 +05:30
|
|
|
rescue Psych::Exception => e
|
2018-12-23 12:14:25 +05:30
|
|
|
raise Loader::FormatError, e.message
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def valid?
|
|
|
|
@config.is_a?(Hash)
|
|
|
|
end
|
|
|
|
|
|
|
|
def load!
|
|
|
|
unless valid?
|
2018-12-23 12:14:25 +05:30
|
|
|
raise Loader::FormatError, 'Invalid configuration format'
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
@config.deep_symbolize_keys
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|