Class: Gallus::Level
Overview
Internal: Log level represented in a coherent way. You can easily compare log levels between each other. You’re also able to get log level by string/symbol name.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.[](name) ⇒ Object
Internal: Returns level defined under given name.
-
.all ⇒ Object
Internal: All log levels.
-
.each(&block) ⇒ Object
Internal: Shorthand to all.each.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(name, id) ⇒ Level
constructor
Internal: Constructor.
- #to_s ⇒ Object
Constructor Details
#initialize(name, id) ⇒ Level
Internal: Constructor. Initializes logger with given name and identifier, then registers it.
25 26 27 28 29 30 |
# File 'lib/gallus/level.rb', line 25 def initialize(name, id) @name, @id = name.to_s, id self.class.const_set(@name, self) self.class.all << self end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'lib/gallus/level.rb', line 22 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/gallus/level.rb', line 22 def name @name end |
Class Method Details
.[](name) ⇒ Object
Internal: Returns level defined under given name.
18 19 20 |
# File 'lib/gallus/level.rb', line 18 def self.[](name) const_get(name.to_s) end |
.all ⇒ Object
Internal: All log levels.
8 9 10 |
# File 'lib/gallus/level.rb', line 8 def self.all @all ||= [] end |
.each(&block) ⇒ Object
Internal: Shorthand to all.each.
13 14 15 |
# File 'lib/gallus/level.rb', line 13 def self.each(&block) self.all.each(&block) end |
Instance Method Details
#<=>(other) ⇒ Object
32 33 34 35 36 |
# File 'lib/gallus/level.rb', line 32 def <=>(other) self.id <=> other.id rescue => err return nil end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/gallus/level.rb', line 38 def to_s name end |