From 719a069e09d552c90676693c7ceb72909e571774 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Wed, 6 Nov 2024 12:47:56 +1300 Subject: [PATCH] Move public interface to `Console::Interface` and extend it into `Console`. --- lib/console.rb | 36 ++------------------------- lib/console/interface.rb | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 34 deletions(-) create mode 100644 lib/console/interface.rb diff --git a/lib/console.rb b/lib/console.rb index 2a2b042..2ddf3b3 100644 --- a/lib/console.rb +++ b/lib/console.rb @@ -7,40 +7,8 @@ # Copyright, 2021, by Cédric Boutillier. require_relative "console/version" -require_relative "console/logger" +require_relative "console/interface" module Console - class << self - def logger - Logger.instance - end - - def logger= instance - Logger.instance= instance - end - - def debug(...) - Logger.instance.debug(...) - end - - def info(...) - Logger.instance.info(...) - end - - def warn(...) - Logger.instance.warn(...) - end - - def error(...) - Logger.instance.error(...) - end - - def fatal(...) - Logger.instance.fatal(...) - end - - def call(...) - Logger.instance.call(...) - end - end + Console.extend(Interface) end diff --git a/lib/console/interface.rb b/lib/console/interface.rb new file mode 100644 index 0000000..219881b --- /dev/null +++ b/lib/console/interface.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright 2024, by Samuel Williams. + +require_relative "logger" + +module Console + # The public logger interface. + module Interface + # Get the current logger instance. + def logger + Logger.instance + end + + # Set the current logger instance. + # + # The current logger instance is assigned per-fiber. + def logger= instance + Logger.instance= instance + end + + # Emit a debug log message. + def debug(...) + Logger.instance.debug(...) + end + + # Emit an informational log message. + def info(...) + Logger.instance.info(...) + end + + # Emit a warning log message. + def warn(...) + Logger.instance.warn(...) + end + + # Emit an error log message. + def error(...) + Logger.instance.error(...) + end + + # Emit a fatal log message. + def fatal(...) + Logger.instance.fatal(...) + end + + # Emit a log message with arbitrary arguments and options. + def call(...) + Logger.instance.call(...) + end + end +end