Sha256: 8c5d6e439da44085d4f30ad37911dcb6b2a719a2664982f96521519e8c450c38

Contents?: true

Size: 958 Bytes

Versions: 8

Compression:

Stored size: 958 Bytes

Contents

require 'pathname'

module Lono
  module Core
    autoload :Config, 'lono/core/config'

    @@config = nil
    def config
      @@config ||= Config.new
    end

    def root
      path = ENV['LONO_ROOT'] || '.'
      Pathname.new(path)
    end

    @@env = nil
    def env
      return @@env if @@env
      ufo_env = env_from_profile(ENV['AWS_PROFILE']) || 'development'
      ufo_env = ENV['LONO_ENV'] if ENV['LONO_ENV'] # highest precedence
      @@env = ufo_env
    end

    private
    # Do not use the Setting class to load the profile because it can cause an
    # infinite loop then if we decide to use Lono.env from within settings class.
    def env_from_profile(aws_profile)
      data = YAML.load_file("#{Lono.root}/config/settings.yml")
      env = data.find do |_env, setting|
        setting ||= {}
        profiles = setting['aws_profiles']
        profiles && profiles.include?(aws_profile)
      end
      env.first if env
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
lono-4.1.0 lib/lono/core.rb
lono-4.0.6 lib/lono/core.rb
lono-4.0.5 lib/lono/core.rb
lono-4.0.4 lib/lono/core.rb
lono-4.0.3 lib/lono/core.rb
lono-4.0.2 lib/lono/core.rb
lono-4.0.1 lib/lono/core.rb
lono-4.0.0 lib/lono/core.rb