debian-mirror-gitlab/lib/gitlab/static_site_editor/config/file_config.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
module Gitlab
module StaticSiteEditor
module Config
2021-01-03 14:25:43 +05:30
#
# Base GitLab Static Site Editor Configuration facade
#
2020-11-24 15:15:51 +05:30
class FileConfig
2021-01-03 14:25:43 +05:30
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.
@global.descendants.map { |descendant| [descendant.key, descendant.config] }.to_h
end
private
def content_hash(yaml)
Gitlab::Config::Loader::Yaml.new(yaml).load!
2020-11-24 15:15:51 +05:30
end
end
end
end
end