Skip to content

Commit

Permalink
Rework enabled? to check for Backend::Interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Aug 25, 2024
1 parent a7e1c59 commit c9ef4d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions lib/metrics/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
require 'console/event/failure'

module Metrics
# Require a specific trace backend.
def self.require_backend(env = ENV)
if backend = env['METRICS_BACKEND']
begin
require(backend)
rescue LoadError => error
::Console::Event::Failure.for(error).emit(self, "Unable to load metrics backend!", backend: backend, severity: :warn)
module Backend
# Require a specific trace backend.
def self.require_backend(env = ENV)
if backend = env['METRICS_BACKEND']
begin
require(backend)
rescue LoadError => error
::Console::Event::Failure.for(error).emit(self, "Unable to load metrics backend!", backend: backend, severity: :warn)
end

Metrics.extend(Backend::Interface)
end

Metrics.extend(Backend::Interface)
end
end
end

Metrics.require_backend
Metrics::Backend.require_backend
2 changes: 1 addition & 1 deletion lib/metrics/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
module Metrics
# @returns [Boolean] Whether there is an active backend.
def self.enabled?
self.const_defined?(:Backend)
Backend.const_defined?(:Interface)
end

module Provider
Expand Down
2 changes: 1 addition & 1 deletion test/metrics/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

require "sus/fixtures/console"

describe Metrics do
describe Metrics::Backend do
with ".require_backend" do
include_context Sus::Fixtures::Console::CapturedLogger

Expand Down

0 comments on commit c9ef4d4

Please sign in to comment.