Module: Forger::Core

Extended by:
Memoist
Included in:
Forger
Defined in:
lib/forger/core.rb

Constant Summary collapse

@@env =
nil

Instance Method Summary collapse

Instance Method Details

#build_rootObject



40
41
42
# File 'lib/forger/core.rb', line 40

def build_root
  Base::BUILD_ROOT
end

#cloudwatch_enabled?(options) ⇒ Boolean

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

Returns:

  • (Boolean)


14
15
16
17
18
# 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

#envObject



33
34
35
36
37
38
# 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

#rootObject



20
21
22
23
# File 'lib/forger/core.rb', line 20

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

#set_aws_profile!Object

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



46
47
48
49
50
51
52
53
54
55
# 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

#settingsObject

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



59
60
61
# File 'lib/forger/core.rb', line 59

def settings
  Setting.new.data
end

#validate_in_project!Object



25
26
27
28
29
30
# 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