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 Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#initialize(config, additional_permitted_classes: [], filename: nil) ⇒ Yaml
constructor
A new instance of Yaml.
- #load! ⇒ Object
- #load_raw! ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(config, additional_permitted_classes: [], filename: nil) ⇒ Yaml
Returns a new instance of Yaml.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gitlab/config/loader/yaml.rb', line 18 def initialize(config, additional_permitted_classes: [], filename: nil) @raw = config @config = YAML.safe_load(config, permitted_classes: [Symbol, *additional_permitted_classes], permitted_symbols: [], aliases: true, filename: filename ) rescue Psych::Exception => e raise Loader::FormatError, e. end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
16 17 18 |
# File 'lib/gitlab/config/loader/yaml.rb', line 16 def raw @raw end |
Instance Method Details
#blank? ⇒ Boolean
45 46 47 |
# File 'lib/gitlab/config/loader/yaml.rb', line 45 def blank? @config.blank? end |
#load! ⇒ Object
41 42 43 |
# File 'lib/gitlab/config/loader/yaml.rb', line 41 def load! @symbolized_config ||= load_raw!.deep_symbolize_keys end |
#load_raw! ⇒ Object
34 35 36 37 38 39 |
# File 'lib/gitlab/config/loader/yaml.rb', line 34 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
30 31 32 |
# File 'lib/gitlab/config/loader/yaml.rb', line 30 def valid? hash? && !too_big? end |