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”.
-
#get_containers_by_given_name(given_name) ⇒ Object
Select containers based on its given name (ignore basename).
-
#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 21 22 23 24 25 |
# File 'lib/docker-compose/models/compose.rb', line 17 def add_container(container) # Avoid duplicated labels on compose while @containers.has_key?(container.attributes[:label]) do container.attributes[:label].succ! end @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
102 103 104 105 |
# File 'lib/docker-compose/models/compose.rb', line 102 def delete(labels = []) call_container_method(:delete, labels) delete_containers_entries(labels) end |
#get_containers_by(params) ⇒ Object
Select containers based on attributes given by “params”
30 31 32 33 34 |
# File 'lib/docker-compose/models/compose.rb', line 30 def get_containers_by(params) @containers.values.select do |container| (params.to_a - container.attributes.to_a).empty? end end |
#get_containers_by_given_name(given_name) ⇒ Object
Select containers based on its given name (ignore basename)
40 41 42 43 44 |
# File 'lib/docker-compose/models/compose.rb', line 40 def get_containers_by_given_name(given_name) @containers.select { |label, container| container.attributes[:name].match(/#{ComposeUtils.dir_name}_#{given_name}_\d+/) }.values 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
91 92 93 |
# File 'lib/docker-compose/models/compose.rb', line 91 def kill(labels = []) call_container_method(:kill, labels) end |
#link_containers ⇒ Object
Create link relations among containers
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/docker-compose/models/compose.rb', line 49 def link_containers @containers.each_value do |container| links = container.attributes[:links] next if (container.loaded_from_environment? or 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
69 70 71 |
# File 'lib/docker-compose/models/compose.rb', line 69 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
80 81 82 |
# File 'lib/docker-compose/models/compose.rb', line 80 def stop(labels = []) call_container_method(:stop, labels) end |