Sha256: 2e715fb186d3ab34fa4e481b3954e9e0c8923da232f3c9ad553e154b0017d30f

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

require "thor"

module Fontist
  module Utils
    class UI < Thor
      ALL_LEVELS = %i[debug info warn error fatal unknown].freeze

      def self.level=(level)
        unless ALL_LEVELS.include?(level)
          raise Errors::GeneralError,
                "Unknown log level: #{level.inspect}. " \
                "Supported levels are #{ALL_LEVELS.map(&:inspect).join(', ')}."
        end

        @level = level
      end

      def self.level
        @level || default_level
      end

      def self.default_level
        :fatal
      end

      def self.success(message)
        new.say(message, :green) if log_levels.include?(:info)
      end

      def self.error(message)
        new.say(message, :red) if log_levels.include?(:warn)
      end

      def self.say(message)
        new.say(message) if log_levels.include?(:info)
      end

      def self.ask(message, options = {})
        new.ask(message, options)
      end

      def self.print(message)
        super if log_levels.include?(:info)
      end

      def self.debug(message)
        new.say(message) if log_levels.include?(:debug)
      end

      def self.log_levels
        @log_levels ||= {}
        @log_levels[@level] ||= ALL_LEVELS.drop_while { |l| l != level }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fontist-1.14.4 lib/fontist/utils/ui.rb
fontist-1.14.3 lib/fontist/utils/ui.rb
fontist-1.14.2 lib/fontist/utils/ui.rb
fontist-1.14.1 lib/fontist/utils/ui.rb
fontist-1.14.0 lib/fontist/utils/ui.rb
fontist-1.13.2 lib/fontist/utils/ui.rb