Class: Opsicle::List

Inherits:
Object
  • Object
show all
Defined in:
lib/opsicle/commands/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ List

Returns a new instance of List.



7
8
9
# File 'lib/opsicle/commands/list.rb', line 7

def initialize(environment)
  @client = Client.new(environment)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/opsicle/commands/list.rb', line 5

def client
  @client
end

Instance Method Details

#app_data(apps) ⇒ Object



33
34
35
# File 'lib/opsicle/commands/list.rb', line 33

def app_data(apps)
  apps.map{|app| [app[:name], app[:stack_id], app[:app_id]] }
end

#apps_for_stack(stack_id) ⇒ Object



25
26
27
# File 'lib/opsicle/commands/list.rb', line 25

def apps_for_stack(stack_id)
  client.api_call('describe_apps', stack_id: stack_id)[:apps]
end

#execute(options = {}) ⇒ Object



11
12
13
14
15
# File 'lib/opsicle/commands/list.rb', line 11

def execute(options={})
  stack_ids = get_stacks
  apps = get_apps(stack_ids)
  print(apps)
end

#get_apps(stack_ids) ⇒ Object



21
22
23
# File 'lib/opsicle/commands/list.rb', line 21

def get_apps(stack_ids)
  stack_ids.map{ |stack_id| apps_for_stack(stack_id) }.flatten
end

#get_stacksObject



17
18
19
# File 'lib/opsicle/commands/list.rb', line 17

def get_stacks
  client.api_call('describe_stacks')[:stacks].map{|s| s[:stack_id] }
end


29
30
31
# File 'lib/opsicle/commands/list.rb', line 29

def print(apps)
  puts Terminal::Table.new headings: ['Name', 'Stack Id', 'App Id'], rows: app_data(apps)
end