Class: Kitsune::Kit::EnvLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/kitsune/kit/env_loader.rb

Class Method Summary collapse

Class Method Details

.load!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kitsune/kit/env_loader.rb', line 7

def self.load!
  return if @loaded

  env = ENV["KIT_ENV"] || read_kit_env || "development"

  possible_paths = [
    ".kitsune/infra.#{env}.env",
    ".kitsune/infra.env"
  ]

  found = possible_paths.find { |path| File.exist?(path) }

  if found
    Dotenv.load(found)
    puts AnsiColor.colorize("๐Ÿงช Loaded Kitsune environment from #{found}", color: :light_cyan)
    puts AnsiColor.colorize("=======================================================================\n", color: :light_cyan)
  else
    puts "โš ๏ธ  No Kitsune infra config found for environment '#{env}' (looked for infra.#{env}.env and infra.env)"
  end

  @loaded = true
end

.read_kit_envObject



30
31
32
33
34
35
36
37
38
# File 'lib/kitsune/kit/env_loader.rb', line 30

def self.read_kit_env
  path = ".kitsune/kit.env"
  if File.exist?(path)
    vars = Dotenv.parse(path)
    vars["KIT_ENV"]
  else
    nil
  end
end