Class: Dome::Environment
- Inherits:
-
Object
- Object
- Dome::Environment
- Defined in:
- lib/dome/environment.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#ecosystem ⇒ Object
readonly
Returns the value of attribute ecosystem.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
- #accounts ⇒ Object
- #aws_credentials ⇒ Object
- #environments ⇒ Object
-
#initialize(directories = Dir.pwd.split('/')) ⇒ Environment
constructor
A new instance of Environment.
- #invalid_account_message ⇒ Object
- #invalid_environment_message ⇒ Object
- #project ⇒ Object
- #unset_aws_keys ⇒ Object
- #valid_account?(account_name) ⇒ Boolean
- #valid_environment?(environment_name) ⇒ Boolean
Constructor Details
#initialize(directories = Dir.pwd.split('/')) ⇒ Environment
Returns a new instance of Environment.
5 6 7 8 9 10 |
# File 'lib/dome/environment.rb', line 5 def initialize(directories = Dir.pwd.split('/')) @environment = directories[-1] @account = directories[-2] @ecosystem = directories[-2].split('-')[-1] @settings = Dome::Settings.new end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
3 4 5 |
# File 'lib/dome/environment.rb', line 3 def account @account end |
#ecosystem ⇒ Object (readonly)
Returns the value of attribute ecosystem.
3 4 5 |
# File 'lib/dome/environment.rb', line 3 def ecosystem @ecosystem end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
3 4 5 |
# File 'lib/dome/environment.rb', line 3 def environment @environment end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
3 4 5 |
# File 'lib/dome/environment.rb', line 3 def settings @settings end |
Instance Method Details
#accounts ⇒ Object
16 17 18 |
# File 'lib/dome/environment.rb', line 16 def accounts %W(#{project}-dev #{project}-prd) end |
#aws_credentials ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/dome/environment.rb', line 31 def aws_credentials puts "Setting environment variable #{'AWS_PROFILE'.colorize(:green)} to your "\ "'account' name: #{@account.colorize(:green)}" ENV['AWS_PROFILE'] = @account puts "Setting environment variable #{'AWS_DEFAULT_REGION'.colorize(:green)} "\ "to #{'eu-west-1'.colorize(:green)}" ENV['AWS_DEFAULT_REGION'] = 'eu-west-1' # should we let people override this? doubtful end |
#environments ⇒ Object
20 21 22 |
# File 'lib/dome/environment.rb', line 20 def environments @settings.parse['environments'] end |
#invalid_account_message ⇒ Object
50 51 52 53 54 |
# File 'lib/dome/environment.rb', line 50 def puts "\n'#{@account}' is not a valid account.\n".colorize(:red) exit 1 end |
#invalid_environment_message ⇒ Object
56 57 58 59 60 |
# File 'lib/dome/environment.rb', line 56 def puts "\n'#{@environment}' is not a valid environment.\n".colorize(:red) exit 1 end |
#project ⇒ Object
12 13 14 |
# File 'lib/dome/environment.rb', line 12 def project @settings.parse['project'] end |
#unset_aws_keys ⇒ Object
24 25 26 27 28 29 |
# File 'lib/dome/environment.rb', line 24 def unset_aws_keys puts 'Unsetting environment variables '\ "#{'AWS_ACCESS_KEY'.colorize(:green)} and #{'AWS_SECRET_KEY'.colorize(:green)}" ENV['AWS_ACCESS_KEY'] = nil ENV['AWS_SECRET_KEY'] = nil end |
#valid_account?(account_name) ⇒ Boolean
40 41 42 43 |
# File 'lib/dome/environment.rb', line 40 def valid_account?(account_name) puts "Account: #{account_name.colorize(:green)}" accounts.include? account_name end |
#valid_environment?(environment_name) ⇒ Boolean
45 46 47 48 |
# File 'lib/dome/environment.rb', line 45 def valid_environment?(environment_name) puts "Environment: #{environment_name.colorize(:green)}" environments.include? environment_name end |