Module: NexClient::Commands::CubeTemplates

Extended by:
Helpers
Defined in:
lib/nex_client/commands/cube_templates.rb

Constant Summary collapse

TEMPLATES_TITLE =
"Cube Templates".colorize(:red)
TEMPLATES_HEADERS =
['id','name','image','tag','layer','min_pu','stack'].map(&:upcase)

Constants included from Helpers

Helpers::LOG_COLORS

Class Method Summary collapse

Methods included from Helpers

display_logs, display_record_errors, error, success

Class Method Details

.display_templates(list) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/nex_client/commands/cube_templates.rb', line 28

def self.display_templates(list)
  table = Terminal::Table.new title: TEMPLATES_TITLE, headings: TEMPLATES_HEADERS do |t|
    [list].flatten.compact.each do |e|
      t.add_row(self.format_record(e))
    end
  end
  puts table
  puts "\n"
end

.format_record(record) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/nex_client/commands/cube_templates.rb', line 38

def self.format_record(record)
  [
    record.id,
    record.human_id,
    record.image,
    record.tag,
    record.layer,
    record.min_pu,
    record.stack
  ]
end

.list(args, opts) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nex_client/commands/cube_templates.rb', line 10

def self.list(args,opts)
  filters = {}
  filters[:human_id] = opts.name if opts.name.present?
  filters[:stack] = opts.stack if opts.stack.present?
  filters[:image] = opts.image if opts.image.present?

  # Create table
  list = NexClient::CubeTemplate.where(filters).order('human_id')
  self.display_templates(list)

  # Loop through results
  while (list.pages.links||{})['next']
    ask("Press enter for next page")
    list = list.pages.next
    self.display_templates(list)
  end
end