Module: Plankton::Helpers

Defined in:
lib/plankton/helpers.rb

Instance Method Summary collapse

Instance Method Details

#detailed_tags_table(tags) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/plankton/helpers.rb', line 22

def detailed_tags_table(tags)
  return if tags.size.zero?
  headers = ['Image tag', 'Created at', 'Size']
  tags = tags.sort_by { |t| t.created_at }.reverse
  rows = tags.map do |tag|
    [
      tag.tag,
      tag.created_at.to_s,
      pretty_size(tag.layer_size)
    ]
  end
  puts TTY::Table.new(headers, rows).render(:basic)
end

#optsObject



3
4
5
# File 'lib/plankton/helpers.rb', line 3

def opts
  @opts_struct ||= RecursiveOpenStruct.new(options)
end

#pretty_size(bytes) ⇒ Object



18
19
20
# File 'lib/plankton/helpers.rb', line 18

def pretty_size(bytes)
  Filesize.from("#{bytes} B").pretty
end

#registryObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/plankton/helpers.rb', line 7

def registry
  unless username? || password?
    return @registry ||= DockerRegistry2.connect(hostname,
                                                 verbose: verbose?)
  end
  @registry ||= DockerRegistry2.connect(hostname,
                                        verbose: verbose?,
                                        user: username,
                                        password: password)
end

#total_size(tags) ⇒ Object



36
37
38
# File 'lib/plankton/helpers.rb', line 36

def total_size(tags)
  pretty_size(tags.reduce(0) { |sum, t| sum + t.layer_size })
end