Module: Unifig::Init

Defined in:
lib/unifig/init.rb

Overview

Initializes Unifig with methods based on YAML.

Class Method Summary collapse

Class Method Details

.load(str, env: nil) ⇒ Object

Loads a string of YAML to configure Unifig.

Examples:

Unifig::Init.load("config:\n  envs:\n    development:\n      providers: local\n\nFOO_BAR:\n  value: \"baz\"\n", env: :development)

Raises:



27
28
29
30
31
32
# File 'lib/unifig/init.rb', line 27

def load(str, env: nil)
  yml = Psych.load(str, symbolize_names: true)
  exec!(yml, env: env)
rescue Psych::SyntaxError, Psych::BadAlias => e
  raise YAMLSyntaxError, e.message
end

.load_file(file_path, env: nil) ⇒ Object

Loads a YAML file to configure Unifig.

Examples:

Unifig::Init.load_file('config.yml', env: :development)

Raises:



43
44
45
46
47
# File 'lib/unifig/init.rb', line 43

def load_file(file_path, env: nil)
  # Ruby 2.7 Psych.load_file doesn't support the :symbolize_names flag.
  # After Ruby 2.7 this can be changed to Psych.load_file if that's faster.
  load(File.read(file_path), env: env)
end