module AwsEc2::Core
Public Instance Methods
config()
click to toggle source
# File lib/aws_ec2/core.rb, line 7 def config @@config ||= Config.new.data end
env()
click to toggle source
# File lib/aws_ec2/core.rb, line 28 def env return @@env if @@env env = env_from_profile(ENV['AWS_PROFILE']) || 'development' env = ENV['AWS_EC2_ENV'] if ENV['AWS_EC2_ENV'] # highest precedence @@env = env end
root()
click to toggle source
# File lib/aws_ec2/core.rb, line 15 def root path = ENV['AWS_EC2_ROOT'] || '.' Pathname.new(path) end
settings()
click to toggle source
# File lib/aws_ec2/core.rb, line 11 def settings Setting.new.data end
validate_in_project!()
click to toggle source
# File lib/aws_ec2/core.rb, line 20 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 aws-ec2 project. Please confirm that you are in a aws-ec2 project and try again.".colorize(: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 AwsEc2.env from within settings class.
# File lib/aws_ec2/core.rb, line 38 def env_from_profile(aws_profile) settings_path = "#{AwsEc2.root}/config/settings.yml" return unless File.exist?(settings_path) data = YAML.load_file(settings_path) env = data.find do |_env, setting| setting ||= {} profiles = setting['aws_profiles'] profiles && profiles.include?(aws_profile) end env.first if env end