class Devup::ServicePresenter

Attributes

project[R]
service[R]

Public Class Methods

new(service, project: nil) click to toggle source
# File lib/devup/service_presenter.rb, line 5
def initialize(service, project: nil)
  @service = service
  @project = project
end

Public Instance Methods

call() click to toggle source
# File lib/devup/service_presenter.rb, line 10
def call
  res = []

  res << "# #{service.name}"

  if has_ports?
    res << host_env
    res << ports_env
  else
    res << "# no exposed ports"
  end

  res.join "\n"
end

Private Instance Methods

database_name() click to toggle source
# File lib/devup/service_presenter.rb, line 59
def database_name
  "db"
end
has_ports?() click to toggle source
# File lib/devup/service_presenter.rb, line 51
def has_ports?
  service.ports.size > 0
end
host_env() click to toggle source
# File lib/devup/service_presenter.rb, line 27
def host_env
  "export #{service.name.upcase}_HOST=0.0.0.0"
end
port_env(from: nil, to:) click to toggle source
# File lib/devup/service_presenter.rb, line 43
def port_env(from: nil, to:)
  if from.nil?
    "export #{service.name.upcase}_PORT=#{to}"
  else
    "export #{service.name.upcase}_PORT_#{from}=#{to}"
  end
end
port_to(from) click to toggle source
# File lib/devup/service_presenter.rb, line 55
def port_to(from)
  service.ports.find { |p| p.from == from }&.to
end
ports_env() click to toggle source
# File lib/devup/service_presenter.rb, line 31
def ports_env
  res = []

  res << port_env(to: service.ports.first.to)

  service.ports.each do |port|
    res << port_env(from: port.from, to: port.to)
  end

  res.join "\n"
end