class Pantheios::FrontEnds::ThresholdFrontEnd

A class that fulfils the Pantheios FrontEnd protocol that implements severity_logged? based on a threshold specified to the initialiser

NOTE: The FrontEnd protocol is implemented by a class that provides the instance method +severity_logged?(severity : Object)+

Attributes

threshold[R]

Public Class Methods

new(threshold_severity, **options) click to toggle source

Initialises the instance

Signature

  • Parameters:

    • threshold_severity [ ::Symbol ] The threshold severity

  • Options:

    • value_lookup_map [ ::Hash ] A map that is used to lookup severity values (that are not ::Integer) in severity_logged?. May be nil, in which case ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES is used

  • Exceptions:

    • ::TypeError raised if a value given for :value_lookup_map is not a ::hash

# File lib/pantheios/front_ends/threshold_front_end.rb, line 80
def initialize(threshold_severity, **options)

        m = options[:value_lookup_map]

        raise TypeError, "value given for :value_lookup_map must be a #{::Hash}" if m && !m.respond_to?(:to_hash)

        if m

                @value_lookup_map = m
                @relativity_lookup_map = ::Hash.new(:relative)
        else

                @value_lookup_map = ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES
                @relativity_lookup_map = ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVELS_RELATIVE
        end

        self.threshold = threshold_severity
end

Public Instance Methods

severity_logged?(severity) click to toggle source

Determines whether a given severity is logged

Signature

  • Parameters:

    • severity

      The severity level, which should be a known log

    severity symbol or an integral equivalent

  • Returns: a truey value if the severity should be logged; a falsey value otherwise

# File lib/pantheios/front_ends/threshold_front_end.rb, line 110
def severity_logged? severity

        case severity
        when ::Integer

                v = severity
        else

                v = @value_lookup_map[severity] or warn "unknown severity level '#{severity}' (#{severity.class})"
        end

        return true if v.nil?

        v <= @threshold_v
end
threshold=(threshold_severity) click to toggle source

assigns the threshold

  • Parameters:

    • threshold_severity [ ::Symbol ] The threshold severity

# File lib/pantheios/front_ends/threshold_front_end.rb, line 130
def threshold=(threshold_severity)

        raise TypeError, "threshold_severity must be a #{::Symbol}" unless ::Symbol === threshold_severity

        @threshold_v = @value_lookup_map[threshold_severity] if @relativity_lookup_map[threshold_severity] or raise ArgumentError, "unknown threshold severity level '#{threshold_severity}' (#{threshold_severity.class})"
        @threshold = threshold_severity

        nil
end