1class HealthCheck
 
2  CUSTOM_ITEMS = %w(hostname url client_ip localtime utctime)
 
3  BOOLEAN_ITEMS = %w(database_connection database_persistence database_integrity)
 
4
 
5  TEST_SETTINGS_KEY = 'healthcheck_test_key'
 
6
 
7  def self.checkup(env)
 
8    new(env).checkup
 
 9  end
 
  • Complexity 1 » saikuro
11  def initialize(env)
 
12    @env = env
 
13  end
 
  • DuplicateMethodCall - calls 'self.send(symptom)' 2 times » reek
  • TooManyStatements - has approx 6 statements » reek
  • Complexity 3 » saikuro
15  def checkup
 
16    diagnosis = {}
 
17    CUSTOM_ITEMS.each do |symptom|
 
18      diagnosis[symptom] = self.send(symptom)
 
19    end
 
20    BOOLEAN_ITEMS.each do |symptom|
 
21      diagnosis[symptom] = stringify(self.send(symptom))
 
22    end
 
23    diagnosis
 
24  end
 
 
26  private
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
28  def hostname
 
29    Socket.gethostname
 
30  end
 
  • Complexity 1 » saikuro
32  def url
 
33    @env.fetch('REQUEST_URI', 'FAILED: no REQUEST_URI present in env')
 
34  end
 
  • Complexity 1 » saikuro
36  def client_ip
 
37    @env.fetch('REMOTE_ADDR', 'FAILED: no REMOTE_ADDR present in env')
 
38  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
40  def localtime
 
41    Time.current.rfc2822
 
42  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
44  def utctime
 
45    Time.current.getutc.rfc2822
 
46  end
 
  • ControlParameter - is controlled by argument 'b' » reek
  • UncommunicativeParameterName - has the parameter name 'b' » reek
  • Complexity 2 » saikuro
48  def stringify(b)
 
49    b ? 'OK' : 'FAILED'
 
50  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 2 » saikuro
52  def database_connection
 
53    ActiveRecord::Base.establish_connection
 
54    ActiveRecord::Base.connection
 
55    true
 
56  rescue
 
57    false
 
58  end
 
  • Complexity 5 » saikuro
60  def database_persistence
 
61    return false unless database_connection
 
62    return false unless Site.first_or_create
 
63    return false unless Site.last_checked_at!
 
64    true
 
65  rescue
 
66    false
 
67  end
 
  • Complexity 2 » saikuro
69  def database_integrity
 
70    return false unless database_connection
 
71    !ActiveRecord::Migrator.needs_migration?
 
72  end
 
73end