Class: Smplkit::LogLevel
- Inherits:
-
Object
- Object
- Smplkit::LogLevel
- Includes:
- Comparable
- Defined in:
- lib/smplkit/log_level.rb
Overview
Log severity levels used by the Smpl Logging service.
Acts as a string-valued enum: each constant equals its name when used in string contexts, and supports comparison via the ordinal.
Constant Summary collapse
- NAMES =
%w[TRACE DEBUG INFO WARN ERROR FATAL SILENT].freeze
- TRACE =
new("TRACE", 0)
- DEBUG =
new("DEBUG", 1)
- INFO =
new("INFO", 2)
- WARN =
new("WARN", 3)
- ERROR =
new("ERROR", 4)
- FATAL =
new("FATAL", 5)
- SILENT =
new("SILENT", 6)
- ALL =
[TRACE, DEBUG, INFO, WARN, ERROR, FATAL, SILENT].freeze
- BY_NAME =
ALL.to_h { |lvl| [lvl.name, lvl] }.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ordinal ⇒ Object
readonly
Returns the value of attribute ordinal.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name, ordinal) ⇒ LogLevel
constructor
A new instance of LogLevel.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(name, ordinal) ⇒ LogLevel
Returns a new instance of LogLevel.
13 14 15 16 17 |
# File 'lib/smplkit/log_level.rb', line 13 def initialize(name, ordinal) @name = name.freeze @ordinal = ordinal freeze end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/smplkit/log_level.rb', line 11 def name @name end |
#ordinal ⇒ Object (readonly)
Returns the value of attribute ordinal.
11 12 13 |
# File 'lib/smplkit/log_level.rb', line 11 def ordinal @ordinal end |
Class Method Details
.coerce(value) ⇒ Object
51 52 53 54 55 |
# File 'lib/smplkit/log_level.rb', line 51 def self.coerce(value) return value if value.is_a?(LogLevel) from_string(value) end |
.from_string(value) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/smplkit/log_level.rb', line 41 def self.from_string(value) raise ArgumentError, "log level cannot be nil" if value.nil? key = value.to_s.upcase level = BY_NAME[key] raise ArgumentError, "unknown log level: #{value.inspect}" unless level level end |
Instance Method Details
#<=>(other) ⇒ Object
25 |
# File 'lib/smplkit/log_level.rb', line 25 def <=>(other) = other.is_a?(LogLevel) ? @ordinal <=> other.ordinal : nil |
#==(other) ⇒ Object
22 |
# File 'lib/smplkit/log_level.rb', line 22 def ==(other) = other.is_a?(LogLevel) ? @ordinal == other.ordinal : @name == other |
#eql?(other) ⇒ Boolean
24 |
# File 'lib/smplkit/log_level.rb', line 24 def eql?(other) = self == other |
#hash ⇒ Object
23 |
# File 'lib/smplkit/log_level.rb', line 23 def hash = @ordinal.hash |
#inspect ⇒ Object
21 |
# File 'lib/smplkit/log_level.rb', line 21 def inspect = "#<Smplkit::LogLevel #{@name}>" |
#to_s ⇒ Object
19 |
# File 'lib/smplkit/log_level.rb', line 19 def to_s = @name |
#to_str ⇒ Object
20 |
# File 'lib/smplkit/log_level.rb', line 20 def to_str = @name |