Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Mazetto <brodock@gmail.com>2017-02-13 02:33:31 +0300
committerGabriel Mazetto <brodock@gmail.com>2017-05-31 15:33:03 +0300
commit500e5227a08bd603a2943c3c7d2efcaf4a40cc15 (patch)
treebb0561e03b6bff783a925c479412dfa043376190 /lib/system_check
parent19ee16a0f85dd4bacddbd066237e62a1bbb7113a (diff)
WIP SystemCheck library for executing checks from a rake task
Diffstat (limited to 'lib/system_check')
-rw-r--r--lib/system_check/base_check.rb42
-rw-r--r--lib/system_check/base_executor.rb18
-rw-r--r--lib/system_check/simple_executor.rb34
3 files changed, 94 insertions, 0 deletions
diff --git a/lib/system_check/base_check.rb b/lib/system_check/base_check.rb
new file mode 100644
index 00000000000..6e9f7e509a9
--- /dev/null
+++ b/lib/system_check/base_check.rb
@@ -0,0 +1,42 @@
+module SystemCheck
+ class BaseCheck
+ def check?
+ raise NotImplementedError
+ end
+
+ def show_error
+ raise NotImplementedError
+ end
+
+ def skip?
+ false
+ end
+
+ def skip_message
+ end
+
+ protected
+
+ def try_fixing_it(*steps)
+ steps = steps.shift if steps.first.is_a?(Array)
+
+ puts ' Try fixing it:'.color(:blue)
+ steps.each do |step|
+ puts " #{step}"
+ end
+ end
+
+ def fix_and_rerun
+ puts ' Please fix the error above and rerun the checks.'.color(:red)
+ end
+
+ def for_more_information(*sources)
+ sources = sources.shift if sources.first.is_a?(Array)
+
+ puts ' For more information see:'.color(:blue)
+ sources.each do |source|
+ puts ' #{source}'
+ end
+ end
+ end
+end
diff --git a/lib/system_check/base_executor.rb b/lib/system_check/base_executor.rb
new file mode 100644
index 00000000000..18319843dea
--- /dev/null
+++ b/lib/system_check/base_executor.rb
@@ -0,0 +1,18 @@
+module SystemCheck
+ class BaseExecutor
+ attr_reader :checks
+ attr_reader :component
+
+ def initialize(component)
+ raise ArgumentError unless component.is_a? String
+
+ @component = component
+ @checks = Set.new
+ end
+
+ def <<(check)
+ raise ArgumentError unless check.is_a? BaseCheck
+ @checks << check
+ end
+ end
+end
diff --git a/lib/system_check/simple_executor.rb b/lib/system_check/simple_executor.rb
new file mode 100644
index 00000000000..2ffe837e326
--- /dev/null
+++ b/lib/system_check/simple_executor.rb
@@ -0,0 +1,34 @@
+module SystemCheck
+ class SimpleExecutor < BaseExecutor
+ def execute
+ start_checking(component)
+
+ @checks.each do |check|
+ print "#{check.name}"
+ if check.skip?
+ puts "skipped #{'('+skip_message+')' if skip_message}".color(:magenta)
+ elsif check.check?
+ puts 'yes'.color(:green)
+ else
+ puts 'no'.color(:red)
+ check.show_error
+ end
+ end
+
+ finished_checking(component)
+ end
+
+ private
+
+ def start_checking(component)
+ puts "Checking #{component.color(:yellow)} ..."
+ puts ''
+ end
+
+ def finished_checking(component)
+ puts ''
+ puts "Checking #{component.color(:yellow)} ... #{"Finished".color(:green)}"
+ puts ''
+ end
+ end
+end