Parent

Included Modules

Yell::Level

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.

@example Set from :info to :error (including)

Yell::Level.new(:info).lte(:error)

@example Set from :info to :error (excluding)

Yell::Level.new(:info).lt(:error)

@example Set at :info only

Yell::Level.new.at(:info)

Constants

InterpretRegexp

Public Class Methods

new( *severities ) click to toggle source

Create a new level instance.

@example Enable all severities

Yell::Level.new

@example Pass the minimum possible severity

Yell::Level.new :warn

@example Pass an array to exactly set the level at the given severities

Yell::Level.new [:info, :error]

@example Pass a range to set the level within the severities

Yell::Level.new (:info..:error)

@param [Integer,String,Symbol,Array,Range,nil] severity The severity for the level.

# File lib/yell/level.rb, line 44
def initialize( *severities )
  set(*severities)
end

Public Instance Methods

<=>( other ) click to toggle source

@private

# File lib/yell/level.rb, line 153
def <=>( other )
  other.is_a?(Numeric) ? to_i <=> other : super
end
==(other) click to toggle source

@private

# File lib/yell/level.rb, line 148
def ==(other)
  other.respond_to?(:severities) ? severities == other.severities : super
end
at( *severities ) click to toggle source

Set the level at specific severities

@example Set at :debug and :error only

at :debug, :error

@return [Yell::Level] the instance

# File lib/yell/level.rb, line 81
def at( *severities )
  severities.each { |severity| calculate! :==, severity }
  self
end
at?( severity ) click to toggle source

Returns whether the level is allowed at the given severity

@example

at? :warn
at? 0       # debug

@return [Boolean] tru or false

# File lib/yell/level.rb, line 69
def at?( severity )
  index = index_from(severity)

  index.nil? ? false : @severities[index]
end
gt( severity ) click to toggle source

Set the level to greater than the given severity

@example Set to :error and above

gt :warn

@return [Yell::Level] the instance

# File lib/yell/level.rb, line 92
def gt( severity )
  calculate! :>, severity
  self
end
gte( severity ) click to toggle source

Set the level greater or equal to the given severity

@example Set to :warn and above

gte :warn

@return [Yell::Level] the instance

# File lib/yell/level.rb, line 103
def gte( severity )
  calculate! :>=, severity
  self
end
inspect() click to toggle source

Get a pretty string representation of the level, including the severities.

# File lib/yell/level.rb, line 137
def inspect
  inspectables = Yell::Severities.select.with_index { |l, i| !!@severities[i] }
  "#<#{self.class.name} severities: #{inspectables * ', '}>"
end
lt( severity ) click to toggle source

Set the level lower than given severity

@example Set to lower than :warn

lt :warn

@return [Yell::Level] the instance

# File lib/yell/level.rb, line 114
def lt( severity )
  calculate! :<, severity
  self
end
lte( severity ) click to toggle source

Set the level lower or equal than given severity

@example Set to lower or equal than :warn

lte :warn

@return [Yell::Level] the instance

# File lib/yell/level.rb, line 125
def lte( severity )
  calculate! :<=, severity
  self
end
set( *severities ) click to toggle source

Set the severity to the given format

# File lib/yell/level.rb, line 49
def set( *severities )
  @severities = Yell::Severities.map { true }
  severity = severities.length > 1 ? severities : severities.first

  case severity
  when Array then at(*severity)
  when Range then gte(severity.first).lte(severity.last)
  when String then interpret(severity)
  when Integer, Symbol then gte(severity)
  when Yell::Level then @severities = severity.severities
  end
end
severities() click to toggle source

@private

# File lib/yell/level.rb, line 143
def severities
  @severities
end
to_i() click to toggle source

to_i implements backwards compatibility

# File lib/yell/level.rb, line 131
def to_i
  @severities.each_with_index { |s,i| return i if s == true }
end
Also aliased as: to_int
to_int() click to toggle source
Alias for: to_i

[Validate]

Generated with the Darkfish Rdoc Generator 2.