Class: Gitlab::Config::Loader::Yaml
- Inherits:
-
Object
- Object
- Gitlab::Config::Loader::Yaml
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/config/loader/yaml.rb
Constant Summary collapse
- DataTooLargeError =
Class.new(Loader::FormatError)
- NotHashError =
Class.new(Loader::FormatError)
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#initialize(config, additional_permitted_classes: []) ⇒ Yaml
constructor
A new instance of Yaml.
- #load! ⇒ Object
- #load_raw! ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(config, additional_permitted_classes: []) ⇒ Yaml
Returns a new instance of Yaml.
16 17 18 19 20 21 22 23 24 |
# File 'lib/gitlab/config/loader/yaml.rb', line 16 def initialize(config, additional_permitted_classes: []) @config = YAML.safe_load(config, permitted_classes: [Symbol, *additional_permitted_classes], permitted_symbols: [], aliases: true ) rescue Psych::Exception => e raise Loader::FormatError, e. end |
Instance Method Details
#blank? ⇒ Boolean
41 42 43 |
# File 'lib/gitlab/config/loader/yaml.rb', line 41 def blank? @config.blank? end |
#load! ⇒ Object
37 38 39 |
# File 'lib/gitlab/config/loader/yaml.rb', line 37 def load! @symbolized_config ||= load_raw!.deep_symbolize_keys end |
#load_raw! ⇒ Object
30 31 32 33 34 35 |
# File 'lib/gitlab/config/loader/yaml.rb', line 30 def load_raw! raise DataTooLargeError, 'The parsed YAML is too big' if too_big? raise NotHashError, 'Invalid configuration format' unless hash? @config end |
#valid? ⇒ Boolean
26 27 28 |
# File 'lib/gitlab/config/loader/yaml.rb', line 26 def valid? hash? && !too_big? end |