Class: Yell::Level
- Inherits:
-
Object
- Object
- Yell::Level
- Defined in:
- lib/yell/level.rb
Overview
The Level
class handles the severities for you in order to determine if an adapter should log or not.
In order to setup your level, you have certain modifiers available:
at :warn # will be set to :warn level only
gt :warn # Will set from :error level onwards
gte :warn # Will set from :warn level onwards
lt :warn # Will set from :info level an below
lte :warn # Will set from :warn level and below
You are able to combine those modifiers to your convenience.
Defined Under Namespace
Modules: Helpers
Constant Summary collapse
- InterpretRegexp =
/(at|gt|gte|lt|lte)?\.?(#{Yell::Severities.join('|')})/i
Instance Attribute Summary collapse
-
#severities ⇒ Object
readonly
Returns the value of attribute severities.
Instance Method Summary collapse
-
#at(*severities) ⇒ Yell::Level
Set the level at specific severities.
-
#at?(severity) ⇒ Boolean
Returns whether the level is allowed at the given severity.
-
#gt(severity) ⇒ Yell::Level
Set the level to greater than the given severity.
-
#gte(severity) ⇒ Yell::Level
Set the level greater or equal to the given severity.
-
#initialize(severity = nil) ⇒ Level
constructor
Create a new level instance.
-
#inspect ⇒ String
Get a pretty string representation of the level, including the severities.
-
#lt(severity) ⇒ Yell::Level
Set the level lower than given severity.
-
#lte(severity) ⇒ Yell::Level
Set the level lower or equal than given severity.
-
#to_i ⇒ Object
(also: #to_int)
to_i implements backwards compatibility.
Constructor Details
#initialize(severity = nil) ⇒ Level
Create a new level instance.
63 64 65 |
# File 'lib/yell/level.rb', line 63 def initialize( severity = nil ) reset!( severity ) end |
Instance Attribute Details
#severities ⇒ Object (readonly)
Returns the value of attribute severities.
46 47 48 |
# File 'lib/yell/level.rb', line 46 def severities @severities end |
Instance Method Details
#at(*severities) ⇒ Yell::Level
Set the level at specific severities.
86 87 88 89 |
# File 'lib/yell/level.rb', line 86 def at( *severities ) severities.each { |severity| calculate! :==, severity } self end |
#at?(severity) ⇒ Boolean
Returns whether the level is allowed at the given severity
74 75 76 77 78 |
# File 'lib/yell/level.rb', line 74 def at?( severity ) index = index_from( severity ) index.nil? ? false : @severities[index] end |
#gt(severity) ⇒ Yell::Level
Set the level to greater than the given severity
97 98 99 100 |
# File 'lib/yell/level.rb', line 97 def gt( severity ) calculate! :>, severity self end |
#gte(severity) ⇒ Yell::Level
Set the level greater or equal to the given severity
108 109 110 111 |
# File 'lib/yell/level.rb', line 108 def gte( severity ) calculate! :>=, severity self end |
#inspect ⇒ String
Get a pretty string representation of the level, including the severities.
148 149 150 151 152 153 154 155 |
# File 'lib/yell/level.rb', line 148 def inspect severities = Yell::Severities.each.with_index.inject( [] ) do |r, (l, i)| r << l if @severities[i] r end "#<#{self.class.name} severities: #{severities * ', '}>" end |
#lt(severity) ⇒ Yell::Level
Set the level lower than given severity
119 120 121 122 |
# File 'lib/yell/level.rb', line 119 def lt( severity ) calculate! :<, severity self end |
#lte(severity) ⇒ Yell::Level
Set the level lower or equal than given severity
130 131 132 133 |
# File 'lib/yell/level.rb', line 130 def lte( severity ) calculate! :<=, severity self end |
#to_i ⇒ Object Also known as: to_int
to_i implements backwards compatibility
136 137 138 |
# File 'lib/yell/level.rb', line 136 def to_i @severities.each_with_index { |s,i| return i if s == true } end |