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

#all_repos, #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, #repository_storage_paths_args, #run_and_match, #run_command, #run_command!, #uid_for, #user_home, #warn_user_is_not_gitlab

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Instance Attribute Details

#skip_reasonString

Skip reason defined during runtime

This value have precedence over the one defined in the subclass

Returns:

  • (String)

    the reason


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

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


85
86
87
# File 'lib/system_check/base_check.rb', line 85

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

#can_skip?Boolean

Returns:

  • (Boolean)

89
90
91
# File 'lib/system_check/base_check.rb', line 89

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)

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

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)

112
113
114
# File 'lib/system_check/base_check.rb', line 112

def multi_check
  raise NotImplementedError
end

#multi_check?Boolean

Returns:

  • (Boolean)

93
94
95
# File 'lib/system_check/base_check.rb', line 93

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)

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

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:


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

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)

137
138
139
# File 'lib/system_check/base_check.rb', line 137

def skip?
  raise NotImplementedError
end