Class: Cody::List

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
AwsServices
Defined in:
lib/cody/list/project.rb,
lib/cody/list.rb

Overview

Wrap project in object to allow lazy loading of status

Defined Under Namespace

Classes: Project

Instance Method Summary collapse

Methods included from AwsServices

#cfn, #codebuild

Methods included from AwsServices::Helpers

#are_you_sure?, #inferred_project_name, #inferred_stack_name, #project_name_convention, #stack_exists?

Constructor Details

#initialize(options) ⇒ List

Returns a new instance of List.



8
9
10
# File 'lib/cody/list.rb', line 8

def initialize(options)
  @options = options
end

Instance Method Details

#list_projectsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cody/list.rb', line 31

def list_projects
  projects = []
  next_token = :start
  while next_token
    options = {sort_by: "NAME"}
    if next_token && next_token != :start
      options[:next_token] = next_token
    end
    resp = codebuild.list_projects(options)
    next_token = resp.next_token
    projects += resp.projects
  end
  projects
end

#projectsObject



26
27
28
# File 'lib/cody/list.rb', line 26

def projects
  list_projects.map { |p| Project.new(p) }
end

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cody/list.rb', line 12

def run
  if projects.size > 15
    puts "Number of projects: #{projects.size}"
    puts "Can take a while for a large number of projects..."
  end

  presenter = CliFormat::Presenter.new(@options)
  presenter.header = ["Name", "Status", "Time"]
  projects.each do |project|
    presenter.rows << [project.name, project.build_status, project.end_time]
  end
  presenter.show
end