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.
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:.
-
#to_i ⇒ Object
(also: #to_int)
to_i implements backwards compatibility.
Constructor Details
#initialize(severity = nil) ⇒ Level
Create a new level instance.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/yell/level.rb', line 44 def initialize( severity = nil ) @severities = Yell::Severities.map { true } # all levels allowed by default case severity when Yell::Level then @severities = severity.severities when Array then at( *severity ) when Range then gte(severity.first).lte(severity.last) when Integer, String, Symbol then gte(severity) end end |
Instance Attribute Details
#severities ⇒ Object (readonly)
Returns the value of attribute severities.
27 28 29 |
# File 'lib/yell/level.rb', line 27 def severities @severities end |
Instance Method Details
#at(*severities) ⇒ Object
:nodoc:
72 73 74 75 |
# File 'lib/yell/level.rb', line 72 def at( *severities ) #:nodoc: severities.each { |severity| calculate! :==, severity } self end |
#at?(severity) ⇒ Boolean
Returns whether the level is allowed at the given severity
60 61 62 63 64 |
# File 'lib/yell/level.rb', line 60 def at?( severity ) index = index_from( severity ) index.nil? ? false : @severities[index] end |
#gt(severity) ⇒ Object
:nodoc:
77 78 79 80 |
# File 'lib/yell/level.rb', line 77 def gt( severity ) #:nodoc: calculate! :>, severity self end |
#gte(severity) ⇒ Object
:nodoc:
82 83 84 85 |
# File 'lib/yell/level.rb', line 82 def gte( severity ) #:nodoc: calculate! :>=, severity self end |
#lt(severity) ⇒ Object
:nodoc:
87 88 89 90 |
# File 'lib/yell/level.rb', line 87 def lt( severity ) #:nodoc: calculate! :<, severity self end |
#lte(severity) ⇒ Object
:nodoc:
92 93 94 95 |
# File 'lib/yell/level.rb', line 92 def lte( severity ) #:nodoc: calculate! :<=, severity self end |
#to_i ⇒ Object Also known as: to_int
to_i implements backwards compatibility
67 68 69 |
# File 'lib/yell/level.rb', line 67 def to_i @severities.each_with_index { |s,i| return i if s == true } end |