Class: Compose
- Inherits:
-
Object
- Object
- Compose
- Defined in:
- lib/docker-compose/models/compose.rb
Instance Attribute Summary collapse
-
#containers ⇒ Object
readonly
Returns the value of attribute containers.
Instance Method Summary collapse
-
#add_container(container) ⇒ Object
Add a new container to compose.
-
#delete(labels = []) ⇒ Object
Delete a container.
-
#get_containers_by(params) ⇒ Object
Select containers based on attributes given by “params”.
-
#initialize ⇒ Compose
constructor
A new instance of Compose.
-
#kill(labels = []) ⇒ Object
Kill a container.
-
#link_containers ⇒ Object
Create link relations among containers.
-
#start(labels = []) ⇒ Object
Start a container.
-
#stop(labels = []) ⇒ Object
Stop a container.
Constructor Details
#initialize ⇒ Compose
Returns a new instance of Compose.
8 9 10 |
# File 'lib/docker-compose/models/compose.rb', line 8 def initialize @containers = {} end |
Instance Attribute Details
#containers ⇒ Object (readonly)
Returns the value of attribute containers.
6 7 8 |
# File 'lib/docker-compose/models/compose.rb', line 6 def containers @containers end |
Instance Method Details
#add_container(container) ⇒ Object
Add a new container to compose
17 18 19 20 |
# File 'lib/docker-compose/models/compose.rb', line 17 def add_container(container) @containers[container.attributes[:label]] = container true end |
#delete(labels = []) ⇒ Object
Delete a container
This method accepts an array of labels. If labels is informed, only those containers with label present in array will be deleted. Otherwise, all containers are deleted
87 88 89 |
# File 'lib/docker-compose/models/compose.rb', line 87 def delete(labels = []) call_container_method(:delete, labels) end |
#get_containers_by(params) ⇒ Object
Select containers based on attributes given by “params”
25 26 27 28 29 |
# File 'lib/docker-compose/models/compose.rb', line 25 def get_containers_by(params) @containers.values.select do |container| (params.to_a - container.attributes.to_a).empty? end end |
#kill(labels = []) ⇒ Object
Kill a container
This method accepts an array of labels. If labels is informed, only those containers with label present in array will be killed. Otherwise, all containers are killed
76 77 78 |
# File 'lib/docker-compose/models/compose.rb', line 76 def kill(labels = []) call_container_method(:kill, labels) end |
#link_containers ⇒ Object
Create link relations among containers
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/docker-compose/models/compose.rb', line 34 def link_containers @containers.each_value do |container| links = container.attributes[:links] next if links.nil? links.each do |service, label| dependency_container = @containers[service] container.add_dependency(dependency_container) end end end |
#start(labels = []) ⇒ Object
Start a container
This method accepts an array of labels. If labels is informed, only those containers with label present in array will be started. Otherwise, all containers are started
54 55 56 |
# File 'lib/docker-compose/models/compose.rb', line 54 def start(labels = []) call_container_method(:start, labels) end |
#stop(labels = []) ⇒ Object
Stop a container
This method accepts an array of labels. If labels is informed, only those containers with label present in array will be stopped. Otherwise, all containers are stopped
65 66 67 |
# File 'lib/docker-compose/models/compose.rb', line 65 def stop(labels = []) call_container_method(:stop, labels) end |