Class: LocalDevelopmentGateway::DatabaseRouter::DockerRoutes

Inherits:
Object
  • Object
show all
Defined in:
lib/local_development_gateway/database_router/docker_routes.rb

Constant Summary collapse

NETWORK_NAME =
"local-gateway"
HOSTNAME_LABEL =
"local-gateway.tcp.hostname"
PORT_LABEL =
"local-gateway.tcp.port"
DRIVER_LABEL =
"local-gateway.tcp.driver"
HOSTNAME_PATTERN =
/\A(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+localhost\z/

Instance Method Summary collapse

Constructor Details

#initialize(client: DatabaseRouter::DockerApi.new) ⇒ DockerRoutes

Returns a new instance of DockerRoutes.



13
14
15
# File 'lib/local_development_gateway/database_router/docker_routes.rb', line 13

def initialize(client: DatabaseRouter::DockerApi.new)
  @client = client
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/local_development_gateway/database_router/docker_routes.rb', line 17

def call
  routes =
    @client
      .get("/containers/json")
      .filter_map { |container| route(container) }
  identities = routes.map { |route| [route.driver, route.hostname] }
  unless identities.uniq.length == identities.length
    raise Error, "Duplicate labelled database hostname"
  end

  routes.sort_by { |route| [route.driver, route.hostname] }
end