Class: ThresholdCheck

Inherits:
Struct
  • Object
show all
Defined in:
lib/cane/threshold_check.rb

Overview

Configurable check that allows the contents of a file to be compared against a given value.

Defined Under Namespace

Classes: UnavailableValue

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#checksObject

Returns the value of attribute checks

Returns:

  • (Object)

    the current value of checks



5
6
7
# File 'lib/cane/threshold_check.rb', line 5

def checks
  @checks
end

Instance Method Details

#value_from_file(file) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/cane/threshold_check.rb', line 16

def value_from_file(file)
  begin
    contents = File.read(file).chomp.to_f
  rescue Errno::ENOENT
    UnavailableValue.new
  end
end

#violationsObject



6
7
8
9
10
11
12
13
14
# File 'lib/cane/threshold_check.rb', line 6

def violations
  checks.map do |operator, file, limit|
    value = value_from_file(file)

    unless value.send(operator, limit.to_f)
      ThresholdViolation.new(file, operator, value, limit)
    end
  end.compact
end