2020-09-10 18:08:54 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module StaticSiteEditor
|
|
|
|
module Config
|
2020-09-29 06:09:45 +00:00
|
|
|
#
|
|
|
|
# Base GitLab Static Site Editor Configuration facade
|
|
|
|
#
|
2020-09-10 18:08:54 +00:00
|
|
|
class FileConfig
|
2020-09-29 06:09:45 +00:00
|
|
|
ConfigError = Class.new(StandardError)
|
|
|
|
|
|
|
|
def initialize(yaml)
|
|
|
|
content_hash = content_hash(yaml)
|
|
|
|
@global = Entry::Global.new(content_hash)
|
|
|
|
@global.compose!
|
|
|
|
rescue Gitlab::Config::Loader::FormatError => e
|
|
|
|
raise FileConfig::ConfigError, e.message
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid?
|
|
|
|
@global.valid?
|
|
|
|
end
|
|
|
|
|
|
|
|
def errors
|
|
|
|
@global.errors
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_hash_with_defaults
|
|
|
|
# NOTE: The current approach of simply mapping all the descendents' keys and values ('config')
|
|
|
|
# into a flat hash may need to be enhanced as we add more complex, non-scalar entries.
|
2021-04-05 18:09:15 +00:00
|
|
|
@global.descendants.to_h { |descendant| [descendant.key, descendant.config] }
|
2020-09-29 06:09:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def content_hash(yaml)
|
|
|
|
Gitlab::Config::Loader::Yaml.new(yaml).load!
|
2020-09-10 18:08:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|