Class: Belt::CLI::EnvironmentConfig
- Inherits:
-
Object
- Object
- Belt::CLI::EnvironmentConfig
- Defined in:
- lib/belt/cli/environment_config.rb
Defined Under Namespace
Classes: BackupDSL, ConfigDSL, ConfigEvaluator, EnvDSL
Instance Attribute Summary collapse
-
#aws_profile ⇒ Object
readonly
Returns the value of attribute aws_profile.
-
#backup_config ⇒ Object
readonly
Returns the value of attribute backup_config.
-
#env_vars ⇒ Object
readonly
Returns the value of attribute env_vars.
Class Method Summary collapse
-
.load(env, infra_dir: nil) ⇒ Object
Load environment config from infrastructure/
/belt.rb Returns an EnvironmentConfig instance (never nil — unconfigured is valid).
Instance Method Summary collapse
-
#apply! ⇒ Object
Apply the configured aws_profile and env vars to the current process.
- #aws_profile? ⇒ Boolean
- #backups? ⇒ Boolean
- #env_vars? ⇒ Boolean
-
#initialize ⇒ EnvironmentConfig
constructor
A new instance of EnvironmentConfig.
Constructor Details
#initialize ⇒ EnvironmentConfig
Returns a new instance of EnvironmentConfig.
22 23 24 25 26 |
# File 'lib/belt/cli/environment_config.rb', line 22 def initialize @aws_profile = nil @env_vars = {} @backup_config = BackupConfig.new end |
Instance Attribute Details
#aws_profile ⇒ Object (readonly)
Returns the value of attribute aws_profile.
6 7 8 |
# File 'lib/belt/cli/environment_config.rb', line 6 def aws_profile @aws_profile end |
#backup_config ⇒ Object (readonly)
Returns the value of attribute backup_config.
6 7 8 |
# File 'lib/belt/cli/environment_config.rb', line 6 def backup_config @backup_config end |
#env_vars ⇒ Object (readonly)
Returns the value of attribute env_vars.
6 7 8 |
# File 'lib/belt/cli/environment_config.rb', line 6 def env_vars @env_vars end |
Class Method Details
.load(env, infra_dir: nil) ⇒ Object
Load environment config from infrastructure/
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/belt/cli/environment_config.rb', line 10 def self.load(env, infra_dir: nil) infra_dir ||= 'infrastructure' config_file = File.join(infra_dir, env, 'belt.rb') config = new return config unless File.exist?(config_file) evaluator = ConfigEvaluator.new(config) evaluator.evaluate(File.read(config_file), config_file) config end |
Instance Method Details
#apply! ⇒ Object
Apply the configured aws_profile and env vars to the current process. Call this before running terraform, aws cli, etc.
42 43 44 45 |
# File 'lib/belt/cli/environment_config.rb', line 42 def apply! ENV['AWS_PROFILE'] = @aws_profile if aws_profile? @env_vars.each { |key, value| ENV[key] = value } end |
#aws_profile? ⇒ Boolean
28 29 30 |
# File 'lib/belt/cli/environment_config.rb', line 28 def aws_profile? !@aws_profile.nil? && !@aws_profile.empty? end |
#backups? ⇒ Boolean
36 37 38 |
# File 'lib/belt/cli/environment_config.rb', line 36 def backups? @backup_config.any? end |
#env_vars? ⇒ Boolean
32 33 34 |
# File 'lib/belt/cli/environment_config.rb', line 32 def env_vars? @env_vars.any? end |