Class: Envirobly::Defaults::Account

Inherits:
Envirobly::Default show all
Includes:
Colorize
Defined in:
lib/envirobly/defaults/account.rb

Constant Summary

Constants included from Colorize

Colorize::BLUE, Colorize::BOLD, Colorize::FAINT, Colorize::GREEN, Colorize::RED, Colorize::RESET, Colorize::YELLOW

Instance Attribute Summary

Attributes inherited from Envirobly::Default

#shell

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Colorize

#bold, #cross, #display_config_errors, #downwards_arrow_to_right, #faint, #green, #green_check, #red, #yellow

Methods inherited from Envirobly::Default

#id, #initialize, key, #require_if_none, #save, #save_if_none

Constructor Details

This class inherits a constructor from Envirobly::Default

Class Method Details

.fileObject



4
# File 'lib/envirobly/defaults/account.rb', line 4

def self.file = "account.yml"

.regexpObject



5
# File 'lib/envirobly/defaults/account.rb', line 5

def self.regexp = /accounts\/(\d+)/

Instance Method Details

#require_idObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/envirobly/defaults/account.rb', line 7

def require_id
  api = Envirobly::Api.new
  accounts = api.list_accounts

  if accounts.object.blank?
    shell.say_error "Please connect an AWS account to your Envirobly account first."
    exit 1
  end

   = accounts.object.first
  id = ["id"]

  if accounts.object.size > 1
    puts "Choose default account to deploy this project to:"

    data = [ [ "ID", "Name", "AWS number", "URL" ] ] +
      accounts.object.pluck("id", "name", "aws_id", "url")

    shell.print_table data, borders: true

    limited_to = accounts.object.pluck("id").map(&:to_s)

    begin
      id = shell.ask("Type in the account ID:", limited_to:).to_i
    rescue Interrupt
      shell.say_error "Cancelled"
      exit
    end

     = accounts.object.find { |a| a["id"] == id }
  end

  save ["url"]

  shell.say "Account ##{id} set as project default "
  shell.say green_check

  id
end