Class: Extension::Features::ArgoConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/project_types/extension/features/argo_config.rb

Constant Summary collapse

CONFIG_FILE_NAME =
"extension.config.yml"

Class Method Summary collapse

Class Method Details

.parse_yaml(context, permitted_keys = []) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/project_types/extension/features/argo_config.rb', line 9

def parse_yaml(context, permitted_keys = [])
  file_name = File.join(context.root, CONFIG_FILE_NAME)

  return {} unless File.size?(file_name)

  begin
    config = YAML.load_file(file_name)

    # `YAML.load_file` returns nil if the file is not empty
    # but does not contain any parsable yml data, e.g. only comments
    # We consider this valid
    return {} if config.nil?

    unless config.is_a?(Hash)
      raise ShopifyCLI::Abort, ShopifyCLI::Context.message("core.yaml.error.not_hash", CONFIG_FILE_NAME)
    end

    config.transform_keys!(&:to_sym)
    assert_valid_config(config, permitted_keys) unless permitted_keys.empty?

    config
  rescue Psych::SyntaxError => e
    raise(
      ShopifyCLI::Abort,
      ShopifyCLI::Context.message("core.yaml.error.invalid", CONFIG_FILE_NAME, e.message)
    )
  end
end