Class: Flotte::Configuration::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/flotte/configuration/service.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_file, host_registry) ⇒ Service

Returns a new instance of Service.



4
5
6
7
# File 'lib/flotte/configuration/service.rb', line 4

def initialize(config_file, host_registry)
  @config_file = config_file
  @host_registry = host_registry
end

Instance Method Details

#buildObject



9
10
11
# File 'lib/flotte/configuration/service.rb', line 9

def build
  self
end

#configObject



41
42
43
# File 'lib/flotte/configuration/service.rb', line 41

def config
  @raw_service_config ||= YAML.safe_load(ERB.new(contents).result)
end

#contentsObject



45
46
47
# File 'lib/flotte/configuration/service.rb', line 45

def contents
  File.read(@config_file)
end

#imageObject



33
34
35
# File 'lib/flotte/configuration/service.rb', line 33

def image
  config["image"]
end

#rolesObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/flotte/configuration/service.rb', line 17

def roles
  @roles ||= config["roles"].map do |role_name, role_config|
    role_environment = service_environment.merge(role_config["environment"] || {})
    Role.new(
      name: role_name,
      service: service,
      environment: role_environment,
      hosts: role_config["hosts"].map { |host_id| @host_registry[host_id] }
    )
  end
end

#serviceObject



13
14
15
# File 'lib/flotte/configuration/service.rb', line 13

def service
  @service ||= Service.new(name: service_name, image: image, default_environment: service_environment)
end

#service_environmentObject



37
38
39
# File 'lib/flotte/configuration/service.rb', line 37

def service_environment
  config["environment"] || {}
end

#service_nameObject



29
30
31
# File 'lib/flotte/configuration/service.rb', line 29

def service_name
  config["name"]
end