module Forger::Core

Public Instance Methods

build_root() click to toggle source
# File lib/forger/core.rb, line 40
def build_root
  Base::BUILD_ROOT
end
cloudwatch_enabled?(options) click to toggle source

cloudwatch cli option takes higher precedence than when its set in the config/settings.yml file.

# File lib/forger/core.rb, line 14
def cloudwatch_enabled?(options)
  !options[:cloudwatch].nil? ?
    options[:cloudwatch] : # options can use symbols because this the options hash from Thor
    settings["cloudwatch"] # settings uses strings as keys
end
env() click to toggle source
# File lib/forger/core.rb, line 33
def env
  return @@env if @@env
  env = env_from_profile(ENV['AWS_PROFILE']) || 'development'
  env = ENV['FORGER_ENV'] if ENV['FORGER_ENV'] # highest precedence
  @@env = env
end
root() click to toggle source
# File lib/forger/core.rb, line 20
def root
  path = ENV['FORGER_ROOT'] || '.'
  Pathname.new(path)
end
set_aws_profile!() click to toggle source

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

# File lib/forger/core.rb, line 46
def set_aws_profile!
  return if ENV['TEST']
  return unless File.exist?("#{Forger.root}/config/settings.yml") # for rake docs
  return unless settings # Only load if within Ufo project and there's a settings.yml
  data = settings[Forger.env] || {}
  if data["aws_profile"]
    puts "Using AWS_PROFILE=#{data["aws_profile"]} from FORGER_ENV=#{Forger.env} in config/settings.yml"
    ENV['AWS_PROFILE'] = data["aws_profile"]
  end
end
settings() click to toggle source
# File lib/forger/core.rb, line 8
def settings
  Setting.new.data
end
validate_in_project!() click to toggle source
# File lib/forger/core.rb, line 25
def validate_in_project!
  unless File.exist?("#{root}/profiles")
    puts "Could not find a profiles folder in the current directory.  It does not look like you are running this command within a forger project.  Please confirm that you are in a forger project and try again.".color(:red)
    exit
  end
end

Private Instance Methods

env_from_profile(aws_profile) click to toggle source

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

# File lib/forger/core.rb, line 69
def env_from_profile(aws_profile)
  return unless settings
  env = settings.find do |_env, settings|
    settings ||= {}
    profiles = settings['aws_profile']
    profiles && profiles == aws_profile
  end
  env.first if env
end