Updated

lib / health_check.rb

A
73 lines of codes
12 methods
3.0 complexity/method
7 churn
35.76 complexity
0 duplications
class HealthCheck
  1. HealthCheck has no descriptive comment
CUSTOM_ITEMS = %w(hostname url client_ip localtime utctime) BOOLEAN_ITEMS = %w(database_connection database_persistence database_integrity) TEST_SETTINGS_KEY = 'healthcheck_test_key' def self.checkup(env) new(env).checkup end def initialize(env) @env = env end def checkup
  1. HealthCheck#checkup has approx 6 statements
diagnosis = {} CUSTOM_ITEMS.each do |symptom| diagnosis[symptom] = self.send(symptom)
  1. HealthCheck#checkup calls 'self.send(symptom)' 2 times Locations: 0 1
end BOOLEAN_ITEMS.each do |symptom| diagnosis[symptom] = stringify(self.send(symptom))
  1. HealthCheck#checkup calls 'self.send(symptom)' 2 times Locations: 0 1
end diagnosis end private def hostname
  1. HealthCheck#hostname doesn't depend on instance state (maybe move it to another class?)
Socket.gethostname end def url @env.fetch('REQUEST_URI', 'FAILED: no REQUEST_URI present in env') end def client_ip @env.fetch('REMOTE_ADDR', 'FAILED: no REMOTE_ADDR present in env') end def localtime
  1. HealthCheck#localtime doesn't depend on instance state (maybe move it to another class?)
Time.current.rfc2822 end def utctime
  1. HealthCheck#utctime doesn't depend on instance state (maybe move it to another class?)
Time.current.getutc.rfc2822 end def stringify(b)
  1. HealthCheck#stringify has the parameter name 'b'
b ? 'OK' : 'FAILED'
  1. HealthCheck#stringify is controlled by argument 'b'
end def database_connection
  1. HealthCheck#database_connection doesn't depend on instance state (maybe move it to another class?)
ActiveRecord::Base.establish_connection ActiveRecord::Base.connection true rescue false end def database_persistence return false unless database_connection return false unless Site.first_or_create return false unless Site.last_checked_at! true rescue false end def database_integrity return false unless database_connection !ActiveRecord::Migrator.needs_migration? end end