Class: Highway::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/highway/interface.rb

Overview

This class is responsible for interfacing with the user (e.g. displaying error messages), using Fastlane UI mechanism underneath.

Instance Method Summary collapse

Constructor Details

#initializeInterface

Initialize an instance.



18
19
20
# File 'lib/highway/interface.rb', line 18

def initialize()
  @history = []
end

Instance Method Details

#error(message) ⇒ Void

Display an error message.

Parameters:

  • message (String)

    The error message.

Returns:

  • (Void)


65
66
67
68
# File 'lib/highway/interface.rb', line 65

def error(message)
  message.to_s.strip.split("\n").each { |line| FastlaneCore::UI.error(line) }
  @history << message.to_s.strip
end

#fatal!(message) ⇒ Void

Display an error message and abort.

Parameters:

  • message (String)

    The error message.

Returns:

  • (Void)


56
57
58
# File 'lib/highway/interface.rb', line 56

def fatal!(message)
  FastlaneCore::UI.user_error!(message.to_s)
end

#header_success(message) ⇒ Void

Display a success header message.

Parameters:

  • message (String)

    The header message.

Returns:

  • (Void)


95
96
97
98
# File 'lib/highway/interface.rb', line 95

def header_success(message)
  whitespace()
  success("--- #{message}".bold)
end

#header_warning(message) ⇒ Void

Display a warning header message.

Parameters:

  • message (String)

    The header message.

Returns:

  • (Void)


105
106
107
108
# File 'lib/highway/interface.rb', line 105

def header_warning(message)
  whitespace()
  warning("--- #{message}".bold)
end

#note(message) ⇒ Void

Display a note message.

Parameters:

  • message (String)

    The note message.

Returns:

  • (Void)


85
86
87
88
# File 'lib/highway/interface.rb', line 85

def note(message)
  message.to_s.strip.split("\n").each { |line| FastlaneCore::UI.message(line) }
  @history << message.to_s.strip
end

#raw(message) ⇒ Void

Display a raw unformatted message.

Parameters:

  • message (String)

    The raw message.

Returns:

  • (Void)


27
28
29
30
# File 'lib/highway/interface.rb', line 27

def raw(message)
  puts(message.to_s)
  @history << message.to_s
end

#success(message) ⇒ Void

Display a success message.

Parameters:

  • message (String)

    The success message.

Returns:

  • (Void)


46
47
48
49
# File 'lib/highway/interface.rb', line 46

def success(message)
  message.to_s.strip.split("\n").each { |line| FastlaneCore::UI.success(line) }
  @history << message.to_s.strip
end

#table(title: nil, headings: [], rows:) ⇒ Void

Display a table padded with whitespace.

Parameters:

  • title (String) (defaults to: nil)

    Table title.

  • headings (Array<String>) (defaults to: [])

    Heading titles.

  • rows (Array<String>)

    Row values.

Returns:

  • (Void)


117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/highway/interface.rb', line 117

def table(title: nil, headings: [], rows:)

  whitespace()

  table = Terminal::Table.new(
    title: title,
    headings: headings,
    rows: FastlaneCore::PrintTable.transform_output(rows)
  )

  raw(table)

  whitespace()

end

#warning(message) ⇒ Void

Display a warning message.

Parameters:

  • message (String)

    The warning message.

Returns:

  • (Void)


75
76
77
78
# File 'lib/highway/interface.rb', line 75

def warning(message)
  message.to_s.strip.split("\n").each { |line| FastlaneCore::UI.important(line) }
  @history << message.to_s.strip
end

#whitespaceVoid

Display a whitespace, unless it’s already displayed.

Returns:

  • (Void)


35
36
37
38
39
# File 'lib/highway/interface.rb', line 35

def whitespace()
  unless (@history.last || "").end_with?("\n")
    raw("\n")
  end
end