Class: Gallus::Level

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/gallus/level.rb

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

Class Method Summary collapse

Instance Method Summary collapse

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

#idObject (readonly)

Returns the value of attribute id.



22
23
24
# File 'lib/gallus/level.rb', line 22

def id
  @id
end

#nameObject (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

.allObject

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_sObject



38
39
40
# File 'lib/gallus/level.rb', line 38

def to_s
  name
end