Module: Lono::Core

Extended by:
Memoist
Included in:
Lono
Defined in:
lib/lono/core.rb,
lib/lono/core/config.rb

Defined Under Namespace

Classes: Config

Constant Summary collapse

@@root =
nil
@@blueprint_root =
nil

Instance Method Summary collapse

Instance Method Details

#blueprint_rootObject



20
# File 'lib/lono/core.rb', line 20

def blueprint_root; @@blueprint_root ; end

#blueprint_root=(v) ⇒ Object



21
# File 'lib/lono/core.rb', line 21

def blueprint_root=(v) ; @@blueprint_root = v ; end

#configObject



7
8
9
# File 'lib/lono/core.rb', line 7

def config
  Config.new
end

#envObject



23
24
25
26
27
28
# File 'lib/lono/core.rb', line 23

def env
  # 2-way binding
  env = env_from_profile(ENV['AWS_PROFILE']) || 'development'
  env = ENV['LONO_ENV'] if ENV['LONO_ENV'] # highest precedence
  env
end

#pro_versionObject



70
71
72
73
# File 'lib/lono/core.rb', line 70

def pro_version
  installed = Gem::Specification.detect { |spec| spec.name == 'lono-pro' }
  installed ? Lono::Pro::VERSION : "not installed"
end

#rootObject



13
14
15
16
# File 'lib/lono/core.rb', line 13

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

#set_aws_profile!Object

Overrides AWS_PROFILE based on the Lono.env if set in configs/settings.yml 2-way binding.



33
34
35
36
37
38
39
40
# File 'lib/lono/core.rb', line 33

def set_aws_profile!
  return unless settings # Only load if within lono project and there's a settings.yml
  data = settings[Lono.env] || {}
  if data["aws_profile"]
    # puts "Using AWS_PROFILE=#{data["aws_profile"]} from LONO_ENV=#{Lono.env} in configs/settings.yml"
    ENV['AWS_PROFILE'] = data["aws_profile"]
  end
end

#settingsObject

Do not use the Setting#data to load the profile because it can cause an infinite loop then if we decide to use Lono.env from within settings class.



61
62
63
64
65
66
67
# File 'lib/lono/core.rb', line 61

def settings
  setting = Setting.new(false) # check_lono_project to account for `lono new`
  settings_path = setting.lookup_project_settings_path
  return unless settings_path # in case outside of lono project

  YAML.load_file(settings_path)
end

#suffixObject

Precedence (highest to lowest)

1. LONO_SUFFIX
2. .current/lono
3. config/settings.yml


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lono/core.rb', line 46

def suffix
  suffix = ENV['LONO_SUFFIX'] # highest precedence
  suffix ||= Cfn::Current.suffix
  unless suffix
    settings = Setting.new.data
    suffix ||= settings["stack_name_suffix"] # lowest precedence
  end

  return if suffix&.empty?
  suffix
end