class Container
Attributes
command[RW]
created[RW]
id[RW]
image_str[RW]
name[RW]
ports[RW]
regexp_name[RW]
regexp_repo[RW]
status[RW]
Public Class Methods
command()
click to toggle source
# File lib/models/container.rb, line 5 def self.command 'docker ps -a' end
create(line)
click to toggle source
# File lib/models/container.rb, line 29 def self.create(line) id, image_str, command, created, status, ports, name = line.chomp.split(' ' * 2).reject(&:empty?).map(&:strip) name, ports = ports, name if name.nil? ret = new( id: id, image_str: image_str, command: command, created: created, status: status, ports: ports, name: name, raw: line ) ret end
find(keyword:, name:, image:)
click to toggle source
# File lib/models/container.rb, line 9 def self.find(keyword:, name:, image:) return all unless keyword || name || image ret = keyword ? search(keyword) : all if image regexp_repo = /#{image}/i ret = ret.select do |container| container.regexp_repo = regexp_repo regexp_repo.match container.image_str end end if name regexp_name = /#{name}/i ret = ret.select do |container| container.regexp_name = regexp_name regexp_name.match container.name end end ret end
new(**params)
click to toggle source
# File lib/models/container.rb, line 45 def initialize(**params) @id = params[:id] @image_str = params[:image_str] @command = params[:command] @created = params[:created] @status = params[:status] @ports = params[:ports] @name = params[:name] @raw = params[:raw] end
Public Instance Methods
del()
click to toggle source
# File lib/models/container.rb, line 56 def del run("docker rm -f #{id}") end
exec(exec_opts, command)
click to toggle source
# File lib/models/container.rb, line 60 def exec(exec_opts, command) [ 'docker exec', exec_opts, id, command ] end
to_s()
click to toggle source
# File lib/models/container.rb, line 69 def to_s @raw.gsub!(@regexp, &:yellow) if @regexp @raw.sub!(/ #{image_str} /) { |_| image_str.gsub(@regexp_repo, '\0'.red) } if @regexp_repo @raw.gsub!(/#{name}$/) { |name| name.gsub(@regexp_name, '\0'.blue) } if @regexp_name @raw end