lib/protoboard/helpers/services_healthcheck_generator.rb in protoboard-0.1.4 vs lib/protoboard/helpers/services_healthcheck_generator.rb in protoboard-0.1.5

- old
+ new

@@ -20,23 +20,35 @@ # } # } # } # ==== # - def call + def call(with_namespace:) circuits_hash = Protoboard::CircuitBreaker.registered_circuits.map do |circuit| state = Protoboard.config.adapter.check_state(circuit.name) { name: circuit.name, status: state, service: circuit.service } end services_hash = circuits_hash .group_by { |circuit| circuit[:service] } .map do |service, circuits_hash| - circuits = circuits_hash.each_with_object({}) { |circuit, memo| memo[circuit[:name]] = circuit[:status] } + + circuits = circuits_hash.each_with_object({}) do |circuit, memo| + circuit_name = format_circuit_name(circuit[:name], with_namespace: with_namespace) + memo[circuit_name] = circuit[:status] + end { service => { 'circuits' => circuits } } end.reduce(:merge) { 'services' => services_hash.to_h } + end + + private + + def format_circuit_name(circuit_name, with_namespace:) + return circuit_name if with_namespace + + circuit_name.sub("#{Protoboard.config.namespace}/", '') end end end end