Class: Container
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#created ⇒ Object
Returns the value of attribute created.
-
#id ⇒ Object
Returns the value of attribute id.
-
#image_str ⇒ Object
Returns the value of attribute image_str.
-
#name ⇒ Object
Returns the value of attribute name.
-
#ports ⇒ Object
Returns the value of attribute ports.
-
#regexp_name ⇒ Object
Returns the value of attribute regexp_name.
-
#regexp_repo ⇒ Object
Returns the value of attribute regexp_repo.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #del ⇒ Object
- #exec(exec_opts, command) ⇒ Object
-
#initialize(**params) ⇒ Container
constructor
A new instance of Container.
- #to_s ⇒ Object
Constructor Details
#initialize(**params) ⇒ Container
Returns a new instance of Container.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/models/container.rb', line 44 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 |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
4 5 6 |
# File 'lib/models/container.rb', line 4 def command @command end |
#created ⇒ Object
Returns the value of attribute created.
4 5 6 |
# File 'lib/models/container.rb', line 4 def created @created end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/models/container.rb', line 4 def id @id end |
#image_str ⇒ Object
Returns the value of attribute image_str.
4 5 6 |
# File 'lib/models/container.rb', line 4 def image_str @image_str end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/models/container.rb', line 4 def name @name end |
#ports ⇒ Object
Returns the value of attribute ports.
4 5 6 |
# File 'lib/models/container.rb', line 4 def ports @ports end |
#regexp_name ⇒ Object
Returns the value of attribute regexp_name.
4 5 6 |
# File 'lib/models/container.rb', line 4 def regexp_name @regexp_name end |
#regexp_repo ⇒ Object
Returns the value of attribute regexp_repo.
4 5 6 |
# File 'lib/models/container.rb', line 4 def regexp_repo @regexp_repo end |
#status ⇒ Object
Returns the value of attribute status.
4 5 6 |
# File 'lib/models/container.rb', line 4 def status @status end |
Class Method Details
.command ⇒ Object
5 6 7 |
# File 'lib/models/container.rb', line 5 def self.command 'docker ps -a' end |
.create(line) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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) 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:) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 |
Instance Method Details
#del ⇒ Object
55 56 57 |
# File 'lib/models/container.rb', line 55 def del run("docker rm -f #{id}") end |
#exec(exec_opts, command) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/models/container.rb', line 59 def exec(exec_opts, command) [ 'docker exec', exec_opts, name, command ] end |
#to_s ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/models/container.rb', line 68 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 |