Class: ChefDK::Policyfile::Reports::Upload

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-dk/policyfile/reports/upload.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reused_cbs: [], uploaded_cbs: [], ui: nil) ⇒ Upload

Returns a new instance of Upload.



29
30
31
32
33
34
35
36
# File 'lib/chef-dk/policyfile/reports/upload.rb', line 29

def initialize(reused_cbs: [], uploaded_cbs: [], ui: nil)
  @reused_cbs = reused_cbs
  @uploaded_cbs = uploaded_cbs
  @ui = ui

  @justify_name_width = nil
  @justify_version_width = nil
end

Instance Attribute Details

#reused_cbsObject (readonly)

Returns the value of attribute reused_cbs.



25
26
27
# File 'lib/chef-dk/policyfile/reports/upload.rb', line 25

def reused_cbs
  @reused_cbs
end

#uiObject (readonly)

Returns the value of attribute ui.



27
28
29
# File 'lib/chef-dk/policyfile/reports/upload.rb', line 27

def ui
  @ui
end

#uploaded_cbsObject (readonly)

Returns the value of attribute uploaded_cbs.



26
27
28
# File 'lib/chef-dk/policyfile/reports/upload.rb', line 26

def uploaded_cbs
  @uploaded_cbs
end

Instance Method Details

#cookbook_namesObject



59
60
61
# File 'lib/chef-dk/policyfile/reports/upload.rb', line 59

def cookbook_names
  (reused_cbs + uploaded_cbs).map { |e| e.lock.name }
end

#cookbook_version_numbersObject



63
64
65
# File 'lib/chef-dk/policyfile/reports/upload.rb', line 63

def cookbook_version_numbers
  (reused_cbs + uploaded_cbs).map { |e| e.lock.version }
end

#showObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/chef-dk/policyfile/reports/upload.rb', line 38

def show
  reused_cbs.each do |cb_with_lock|
    lock = cb_with_lock.lock
    table.print_row("Using", lock.name, lock.version, "(#{lock.identifier[0, 8]})")
  end

  uploaded_cbs.each do |cb_with_lock|
    lock = cb_with_lock.lock
    table.print_row("Uploaded", lock.name, lock.version, "(#{lock.identifier[0, 8]})")
  end
end

#tableObject



50
51
52
53
54
55
56
57
# File 'lib/chef-dk/policyfile/reports/upload.rb', line 50

def table
  @table ||= TablePrinter.new(ui) do |t|
    t.column(%w{ Using Uploaded })
    t.column(cookbook_names)
    t.column(cookbook_version_numbers)
    t.column
  end
end