Class: Dip::Commands::Infra::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/dip/commands/infra/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, git: nil, ref: nil, path: nil) ⇒ Service

Returns a new instance of Service.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dip/commands/infra/service.rb', line 11

def initialize(name, git: nil, ref: nil, path: nil)
  if git.nil? && path.nil?
    raise ArgumentError, "Infra service `#{name}` configuration error: git or path must be defined"
  end

  @name = name
  @git = git
  @ref = ref || "latest"
  @location = if git
    "#{Dip.home_path}/infra/#{@name}/#{@ref}"
  else
    File.expand_path(path)
  end
  @project_name = "dip-infra-#{name}-#{@ref}"
  @network_name = "dip-net-#{name}-#{@ref}"
  @network_env_var = "DIP_INFRA_NETWORK_#{@name.to_s.upcase.tr("-", "_")}"
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



9
10
11
# File 'lib/dip/commands/infra/service.rb', line 9

def git
  @git
end

#locationObject (readonly)

Returns the value of attribute location.



9
10
11
# File 'lib/dip/commands/infra/service.rb', line 9

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/dip/commands/infra/service.rb', line 9

def name
  @name
end

#network_env_varObject (readonly)

Returns the value of attribute network_env_var.



9
10
11
# File 'lib/dip/commands/infra/service.rb', line 9

def network_env_var
  @network_env_var
end

#network_nameObject (readonly)

Returns the value of attribute network_name.



9
10
11
# File 'lib/dip/commands/infra/service.rb', line 9

def network_name
  @network_name
end

#project_nameObject (readonly)

Returns the value of attribute project_name.



9
10
11
# File 'lib/dip/commands/infra/service.rb', line 9

def project_name
  @project_name
end

#refObject (readonly)

Returns the value of attribute ref.



9
10
11
# File 'lib/dip/commands/infra/service.rb', line 9

def ref
  @ref
end

Instance Method Details

#envObject



29
30
31
32
33
34
# File 'lib/dip/commands/infra/service.rb', line 29

def env
  {
    "COMPOSE_PROJECT_NAME" => project_name,
    "DIP_INFRA_NETWORK_NAME" => network_name
  }
end