Class: Gitlab::DowntimeCheck::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/downtime_check/message.rb

Constant Summary collapse

OFFLINE =
"\e[31moffline\e[0m"
ONLINE =
"\e[32monline\e[0m"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, offline = false, reason = nil) ⇒ Message

path - The file path of the migration. offline - When set to `true` the migration will require downtime. reason - The reason as to why the migration requires downtime.


14
15
16
17
18
# File 'lib/gitlab/downtime_check/message.rb', line 14

def initialize(path, offline = false, reason = nil)
  @path = path
  @offline = offline
  @reason = reason
end

Instance Attribute Details

#offlineObject (readonly)

Returns the value of attribute offline


6
7
8
# File 'lib/gitlab/downtime_check/message.rb', line 6

def offline
  @offline
end

#pathObject (readonly)

Returns the value of attribute path


6
7
8
# File 'lib/gitlab/downtime_check/message.rb', line 6

def path
  @path
end

Instance Method Details

#reasonObject


36
37
38
# File 'lib/gitlab/downtime_check/message.rb', line 36

def reason
  @reason.strip.lines.map(&:strip).join("\n")
end

#reason?Boolean

Returns:

  • (Boolean)

32
33
34
# File 'lib/gitlab/downtime_check/message.rb', line 32

def reason?
  @reason.present?
end

#to_sObject


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gitlab/downtime_check/message.rb', line 20

def to_s
  label = offline ? OFFLINE : ONLINE

  message = ["[#{label}]: #{path}"]

  if reason?
    message << ":\n\n#{reason}\n\n"
  end

  message.join
end