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) ⇒ Object
:nodoc:.
-
#at?(severity) ⇒ Boolean
Returns whether the level is allowed at the given severity.
-
#gt(severity) ⇒ Object
:nodoc:.
-
#gte(severity) ⇒ Object
:nodoc:.
-
#initialize(severity = nil) ⇒ Level
constructor
Create a new level instance.
-
#lt(severity) ⇒ Object
:nodoc:.
-
#lte(severity) ⇒ Object
:nodoc:.
- #reset! ⇒ Object
-
#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 66 67 68 69 70 71 72 |
# File 'lib/yell/level.rb', line 63 def initialize( severity = nil ) reset! case severity when Array then at( *severity ) when Range then gte( severity.first ).lte( severity.last ) when Integer, Symbol then gte( severity ) when String then interpret!( severity ) end 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) ⇒ Object
:nodoc:
95 96 97 98 |
# File 'lib/yell/level.rb', line 95 def at( *severities ) #:nodoc: severities.each { |severity| calculate! :==, severity } self end |
#at?(severity) ⇒ Boolean
Returns whether the level is allowed at the given severity
83 84 85 86 87 |
# File 'lib/yell/level.rb', line 83 def at?( severity ) index = index_from( severity ) index.nil? ? false : @severities[index] end |
#gt(severity) ⇒ Object
:nodoc:
100 101 102 103 |
# File 'lib/yell/level.rb', line 100 def gt( severity ) #:nodoc: calculate! :>, severity self end |
#gte(severity) ⇒ Object
:nodoc:
105 106 107 108 |
# File 'lib/yell/level.rb', line 105 def gte( severity ) #:nodoc: calculate! :>=, severity self end |
#lt(severity) ⇒ Object
:nodoc:
110 111 112 113 |
# File 'lib/yell/level.rb', line 110 def lt( severity ) #:nodoc: calculate! :<, severity self end |
#lte(severity) ⇒ Object
:nodoc:
115 116 117 118 |
# File 'lib/yell/level.rb', line 115 def lte( severity ) #:nodoc: calculate! :<=, severity self end |
#reset! ⇒ Object
74 75 76 |
# File 'lib/yell/level.rb', line 74 def reset! @severities = Yell::Severities.map { true } end |
#to_i ⇒ Object Also known as: to_int
to_i implements backwards compatibility
90 91 92 |
# File 'lib/yell/level.rb', line 90 def to_i @severities.each_with_index { |s,i| return i if s == true } end |