Class: SystemCheck::BaseCheck

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/system_check/base_check.rb

Overview

Base class for Checks. You must inherit from here and implement the methods below when necessary

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#finished_checking, #fix_and_rerun, #for_more_information, #omnibus_gitlab?, #sanitized_message, #see_installation_guide_section, #should_sanitize?, #start_checking, #sudo_gitlab, #try_fixing_it

Methods included from Gitlab::TaskHelpers

#ask_to_continue, #checkout_or_clone_version, #checkout_version, #clone_repo, #get_version, #gid_for, #gitlab_user, #gitlab_user?, #invoke_and_time_task, #os_name, #prompt, #prompt_for_password, #repository_storage_paths_args, #run_and_match, #run_command, #run_command!, #uid_for, #user_home, #warn_user_is_not_gitlab

Instance Attribute Details

#skip_reasonString

Define or get a reason why we skipped the SystemCheck (during runtime)

This is used when you need dynamic evaluation like when you have multiple reasons why a check can fail

Parameters:

  • reason (String)

    to be displayed

Returns:

  • (String)

    reason to be displayed



74
75
76
# File 'lib/system_check/base_check.rb', line 74

def skip_reason
  @skip_reason
end

Class Method Details

.check_failString

Term to be displayed when check failed

Returns:

  • (String)

    term when check failed (‘no’ if not re-defined in a subclass)



49
50
51
# File 'lib/system_check/base_check.rb', line 49

def self.check_fail
  call_or_return(@check_fail) || 'no'
end

.check_passString

Term to be displayed when check passed

Returns:

  • (String)

    term when check passed (‘yes’ if not re-defined in a subclass)



42
43
44
# File 'lib/system_check/base_check.rb', line 42

def self.check_pass
  call_or_return(@check_pass) || 'yes'
end

.display_nameString

Name of the SystemCheck defined by the subclass

Returns:

  • (String)

    the name



56
57
58
# File 'lib/system_check/base_check.rb', line 56

def self.display_name
  call_or_return(@name) || self.name
end

.set_check_fail(term) ⇒ Object

Define a custom term for when check failed

Parameters:

  • term (String)

    used when check failed (default: ‘no’)



19
20
21
# File 'lib/system_check/base_check.rb', line 19

def self.set_check_fail(term)
  @check_fail = term
end

.set_check_pass(term) ⇒ Object

Define a custom term for when check passed

Parameters:

  • term (String)

    used when check passed (default: ‘yes’)



12
13
14
# File 'lib/system_check/base_check.rb', line 12

def self.set_check_pass(term)
  @check_pass = term
end

.set_name(name) ⇒ Object

Define the name of the SystemCheck that will be displayed during execution

Parameters:

  • name (String)

    of the check



26
27
28
# File 'lib/system_check/base_check.rb', line 26

def self.set_name(name)
  @name = name
end

.set_skip_reason(reason) ⇒ Object

Define the reason why we skipped the SystemCheck

This is only used if subclass implements ‘#skip?`

Parameters:

  • reason (String)

    to be displayed



35
36
37
# File 'lib/system_check/base_check.rb', line 35

def self.set_skip_reason(reason)
  @skip_reason = reason
end

.skip_reasonString

Skip reason defined by the subclass

Returns:

  • (String)

    the reason



63
64
65
# File 'lib/system_check/base_check.rb', line 63

def self.skip_reason
  call_or_return(@skip_reason) || 'skipped'
end

Instance Method Details

#can_repair?Boolean

Does the check support automatically repair routine?

Returns:

  • (Boolean)

    whether check implemented ‘#repair!` method or not



79
80
81
# File 'lib/system_check/base_check.rb', line 79

def can_repair?
  self.class.instance_methods(false).include?(:repair!)
end

#can_skip?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/system_check/base_check.rb', line 83

def can_skip?
  self.class.instance_methods(false).include?(:skip?)
end

#check?Boolean

Execute the check routine

This is where you should implement the main logic that will return a boolean at the end

You should not print any output to STDOUT here, use the specific methods instead

Returns:

  • (Boolean)

    whether check passed or failed

Raises:

  • (NotImplementedError)


99
100
101
# File 'lib/system_check/base_check.rb', line 99

def check?
  raise NotImplementedError
end

#multi_checkObject

Execute a custom check that cover multiple unities

When using multi_check you have to provide the output yourself

Raises:

  • (NotImplementedError)


106
107
108
# File 'lib/system_check/base_check.rb', line 106

def multi_check
  raise NotImplementedError
end

#multi_check?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/system_check/base_check.rb', line 87

def multi_check?
  self.class.instance_methods(false).include?(:multi_check)
end

#repair!Object

When implemented by a subclass, will attempt to fix the issue automatically

Raises:

  • (NotImplementedError)


124
125
126
# File 'lib/system_check/base_check.rb', line 124

def repair!
  raise NotImplementedError
end

#show_errorObject

Prints troubleshooting instructions

This is where you should print detailed information for any error found during #check?

You may use helper methods to help format the output:



119
120
121
# File 'lib/system_check/base_check.rb', line 119

def show_error
  raise NotImplementedError
end

#skip?Boolean

When implemented by a subclass, will evaluate whether check should be skipped or not

Returns:

  • (Boolean)

    whether or not this check should be skipped

Raises:

  • (NotImplementedError)


131
132
133
# File 'lib/system_check/base_check.rb', line 131

def skip?
  raise NotImplementedError
end