Class: DockerCompose::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/egg/docker_compose/service.rb

Overview

Wraps the definition of docker-compose services

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Service

Returns a new instance of Service.



13
14
15
16
17
18
# File 'lib/egg/docker_compose/service.rb', line 13

def initialize(name)
  @name = name

  @links = []
  @environment = []
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



7
8
9
# File 'lib/egg/docker_compose/service.rb', line 7

def command
  @command
end

#dockerfileObject

Returns the value of attribute dockerfile.



7
8
9
# File 'lib/egg/docker_compose/service.rb', line 7

def dockerfile
  @dockerfile
end

#environmentObject (readonly)

Returns the value of attribute environment.



6
7
8
# File 'lib/egg/docker_compose/service.rb', line 6

def environment
  @environment
end

#imageObject

Returns the value of attribute image.



7
8
9
# File 'lib/egg/docker_compose/service.rb', line 7

def image
  @image
end

Returns the value of attribute links.



6
7
8
# File 'lib/egg/docker_compose/service.rb', line 6

def links
  @links
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/egg/docker_compose/service.rb', line 6

def name
  @name
end

#portsObject

Returns the value of attribute ports.



7
8
9
# File 'lib/egg/docker_compose/service.rb', line 7

def ports
  @ports
end

#volumesObject

Returns the value of attribute volumes.



7
8
9
# File 'lib/egg/docker_compose/service.rb', line 7

def volumes
  @volumes
end

Instance Method Details

#env(variable, value) ⇒ Object



24
25
26
# File 'lib/egg/docker_compose/service.rb', line 24

def env(variable, value)
  @environment << "#{variable}=#{value}"
end


20
21
22
# File 'lib/egg/docker_compose/service.rb', line 20

def link(service)
  @links << service.name
end

#to_hashObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/egg/docker_compose/service.rb', line 28

def to_hash
  output = {
    "environment" => environment,
    "links" => links,
    "volumes" => volumes,
    "ports" => ports
  }

  image ? output["image"] = image : output["build"] = "."
  output["command"] = command if command
  output.each_with_object({}) { |(k, v), hash| hash[k] = v if v }
end