2016-06-03 14:54:33 -04:00
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
2016-06-06 02:20:55 -04:00
|
|
|
class Loader
|
2017-03-01 06:00:37 -05:00
|
|
|
FormatError = Class.new(StandardError)
|
2016-06-03 14:54:33 -04:00
|
|
|
|
|
|
|
def initialize(config)
|
|
|
|
@config = YAML.safe_load(config, [Symbol], [], true)
|
2018-02-04 21:56:16 -05:00
|
|
|
rescue Psych::Exception => e
|
|
|
|
raise FormatError, e.message
|
2016-06-03 14:54:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def valid?
|
|
|
|
@config.is_a?(Hash)
|
|
|
|
end
|
|
|
|
|
2016-06-07 06:53:46 -04:00
|
|
|
def load!
|
2016-06-03 14:54:33 -04:00
|
|
|
unless valid?
|
|
|
|
raise FormatError, 'Invalid configuration format'
|
|
|
|
end
|
|
|
|
|
|
|
|
@config.deep_symbolize_keys
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|