Class: OkComputer::AppVersionCheck

Inherits:
Check
  • Object
show all
Defined in:
lib/ok_computer/built_in_checks/app_version_check.rb

Overview

Display app version SHA

  • If ‘ENV` is set, uses that value.

  • Otherwise, checks for Capistrano’s REVISION file in the app root.

  • Failing these, the check fails

Constant Summary

Constants inherited from Check

Check::CheckNotDefined

Instance Attribute Summary collapse

Attributes inherited from Check

#failure_occurred, #message, #registrant_name, #time

Instance Method Summary collapse

Methods inherited from Check

#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking

Constructor Details

#initialize(file: "REVISION", env: "SHA", &transform) ⇒ AppVersionCheck

Public: Initialize a check for a backed-up Sidekiq queue

file - The path of the version file to check env - The key in ENV to check for a revision SHA transform - The block to optionally transform the version string



17
18
19
20
21
# File 'lib/ok_computer/built_in_checks/app_version_check.rb', line 17

def initialize(file: "REVISION", env: "SHA", &transform)
  self.file = file
  self.env = env
  self.transform = transform || proc { |v| v }
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



9
10
11
# File 'lib/ok_computer/built_in_checks/app_version_check.rb', line 9

def env
  @env
end

#fileObject

Returns the value of attribute file.



8
9
10
# File 'lib/ok_computer/built_in_checks/app_version_check.rb', line 8

def file
  @file
end

#transformObject

Returns the value of attribute transform.



10
11
12
# File 'lib/ok_computer/built_in_checks/app_version_check.rb', line 10

def transform
  @transform
end

Instance Method Details

#checkObject

Public: Return the application version



24
25
26
27
28
29
# File 'lib/ok_computer/built_in_checks/app_version_check.rb', line 24

def check
  mark_message "Version: #{version}"
rescue UnknownRevision
  mark_failure
  mark_message "Unable to determine version"
end

#versionObject

Public: The application version

Returns a String



34
35
36
# File 'lib/ok_computer/built_in_checks/app_version_check.rb', line 34

def version
  transform.call(version_from_env || version_from_file || raise(UnknownRevision))
end