Sha256: 679b87b2bf9b5f44f38206cc58dff9e2f1002c43feaffc084ade07f1c9fda4e5

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

require 'logger'

module Betterlog
  class Log
    class Severity
      include ::Logger::Severity
      include Comparable

      class << self
        thread_local :shared

        def new(name)
          name = name.to_sym if self.class === name
          name = name.to_s.upcase.to_sym
          self.shared ||= {}
          shared[name] ||= super(name).freeze
        end
      end

      def initialize(name)
        name = name.to_sym if self.class === name
        @name = name.to_s.downcase.to_sym
        begin
          @level = self.class.const_get(@name.to_s.upcase)
        rescue NameError
          @name  = :unknown
          @level = UNKNOWN
        end
      end

      def self.all
        @all_constants ||= constants.map { |c| new(c) }
      end

      def to_i
        @level
      end

      def to_s
        @name.to_s.upcase
      end

      def to_sym
        @name
      end

      def as_json(*)
        to_s
      end

      def <=>(other)
        to_i <=> self.class.new(other).to_i
      end

      def eql?(other)
        to_sym == other.to_sym
      end

      alias == eql?

      def hash
        @name.hash
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
betterlog-2.0.4 lib/betterlog/log/severity.rb
betterlog-2.0.3 lib/betterlog/log/severity.rb
betterlog-2.0.2 lib/betterlog/log/severity.rb
betterlog-2.0.1 lib/betterlog/log/severity.rb
betterlog-2.0.0 lib/betterlog/log/severity.rb
betterlog-1.1.1 lib/betterlog/log/severity.rb
betterlog-1.1.0 lib/betterlog/log/severity.rb
betterlog-1.0.0 lib/betterlog/log/severity.rb
betterlog-0.20.3 lib/betterlog/log/severity.rb
betterlog-0.20.2 lib/betterlog/log/severity.rb
betterlog-0.20.1 lib/betterlog/log/severity.rb
betterlog-0.20.0 lib/betterlog/log/severity.rb
betterlog-0.19.0 lib/betterlog/log/severity.rb
betterlog-0.18.0 lib/betterlog/log/severity.rb
betterlog-0.15.2 lib/betterlog/log/severity.rb
betterlog-0.15.1 lib/betterlog/log/severity.rb
betterlog-0.15.0 lib/betterlog/log/severity.rb