Class: Eye::Checker::FileSize

Inherits:
Measure show all
Defined in:
lib/eye/checker/file_size.rb

Constant Summary

Constants inherited from Eye::Checker

TYPES

Instance Attribute Summary

Attributes inherited from Eye::Checker

#check_count, #options, #pid, #process, #type, #value, #values

Instance Method Summary collapse

Methods inherited from Measure

#measure_str

Methods inherited from Eye::Checker

#check, create, #defer, #fire, get_class, #get_value_safe, #inspect, #last_human_values, #logger_sub_tag, #logger_tag, #max_tries, #min_tries, name_and_class, #previous_value, register, requires, #run_in_process_context, validate!

Methods included from Dsl::Validation

included

Constructor Details

#initialize(*args) ⇒ FileSize

Returns a new instance of FileSize.


9
10
11
12
# File 'lib/eye/checker/file_size.rb', line 9

def initialize(*args)
  super
  self.file = process.expand_path(file) if process && file
end

Instance Method Details

#check_nameObject


14
15
16
# File 'lib/eye/checker/file_size.rb', line 14

def check_name
  @check_name ||= "fsize(#{measure_str})"
end

#get_valueObject


18
19
20
# File 'lib/eye/checker/file_size.rb', line 18

def get_value
  File.size(file) rescue nil
end

#good?(value) ⇒ Boolean

Returns:

  • (Boolean)

26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/eye/checker/file_size.rb', line 26

def good?(value)
  return true unless previous_value

  diff = value.to_i - previous_value.to_i

  return true if diff < 0 # case when logger nulled

  return false unless super(diff)
  return false if diff == 0

  true
end

#human_value(value) ⇒ Object


22
23
24
# File 'lib/eye/checker/file_size.rb', line 22

def human_value(value)
  "#{value.to_i / 1024}Kb"
end