Class: U3dCore::Interface

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

Overview

Abstract super class

Direct Known Subclasses

Shell

Defined Under Namespace

Classes: UICrash, UIError

Messaging: show text to the user collapse

Errors: Inputs collapse

Errors: Different kinds of exceptions collapse

Helpers collapse

Instance Method Details

#command(_message) ⇒ Object

Level Command: Print out a terminal command that is being

executed.

By default those messages shown in cyan


77
78
79
# File 'lib/u3d_core/ui/interface.rb', line 77

def command(_message)
  not_implemented(__method__)
end

#command_output(_message) ⇒ Object

Level Command Output: Print the output of a command with

this method

By default those messages shown in magenta


85
86
87
# File 'lib/u3d_core/ui/interface.rb', line 85

def command_output(_message)
  not_implemented(__method__)
end

#confirm(_message) ⇒ Object

A simple yes or no question



119
120
121
# File 'lib/u3d_core/ui/interface.rb', line 119

def confirm(_message)
  not_implemented(__method__)
end

#crash!(exception) ⇒ Object

Pass an exception to this method to exit the program

using the given exception

Use this method instead of user_error! if this error is unexpected, e.g. an invalid server response that shouldn’t happen

Raises:



157
158
159
# File 'lib/u3d_core/ui/interface.rb', line 157

def crash!(exception)
  raise UICrash.new, exception.to_s
end

#deprecated(_message) ⇒ Object

Level Deprecated: Show that a particular function is deprecated

By default those messages shown in strong blue


69
70
71
# File 'lib/u3d_core/ui/interface.rb', line 69

def deprecated(_message)
  not_implemented(__method__)
end

#error(_message) ⇒ Object

Level Error: Can be used to show additional error

information before actually raising an exception
or can be used to just show an error from which
u3d can recover (much magic)

By default those messages are shown in red


39
40
41
# File 'lib/u3d_core/ui/interface.rb', line 39

def error(_message)
  not_implemented(__method__)
end

#header(_message) ⇒ Object

Print a header = a text in a box

use this if this message is really important


100
101
102
# File 'lib/u3d_core/ui/interface.rb', line 100

def header(_message)
  not_implemented(__method__)
end

#important(_message) ⇒ Object

Level Important: Can be used to show warnings to the user

not necessarly negative, but something the user should
be aware of.

By default those messages are shown in yellow


48
49
50
# File 'lib/u3d_core/ui/interface.rb', line 48

def important(_message)
  not_implemented(__method__)
end

#input(_message) ⇒ Object

get a standard text input (single line)



114
115
116
# File 'lib/u3d_core/ui/interface.rb', line 114

def input(_message)
  not_implemented(__method__)
end

#interactive?(_message) ⇒ Boolean

Is is possible to ask the user questions?

Returns:

  • (Boolean)


109
110
111
# File 'lib/u3d_core/ui/interface.rb', line 109

def interactive?(_message)
  not_implemented(__method__)
end

#message(_message) ⇒ Object

Level Message: Show a neutral message to the user

By default those messages shown in white/black


62
63
64
# File 'lib/u3d_core/ui/interface.rb', line 62

def message(_message)
  not_implemented(__method__)
end

#not_implemented(method_name) ⇒ Object



177
178
179
# File 'lib/u3d_core/ui/interface.rb', line 177

def not_implemented(method_name)
  UI.user_error!("Current UI '#{self}' doesn't support method '#{method_name}'")
end

#password(_message) ⇒ Object

Password input for the user, text field shouldn’t show plain text



131
132
133
# File 'lib/u3d_core/ui/interface.rb', line 131

def password(_message)
  not_implemented(__method__)
end

#select(_message, _options) ⇒ Object

Let the user select one out of x items return value is the value of the option the user chose



125
126
127
# File 'lib/u3d_core/ui/interface.rb', line 125

def select(_message, _options)
  not_implemented(__method__)
end

#success(_message) ⇒ Object

Level Success: Show that something was successful

By default those messages are shown in green


55
56
57
# File 'lib/u3d_core/ui/interface.rb', line 55

def success(_message)
  not_implemented(__method__)
end

#to_sObject



181
182
183
# File 'lib/u3d_core/ui/interface.rb', line 181

def to_s
  self.class.name.split('::').last
end

#user_error!(error_message, options = {}) ⇒ Object

Use this method to exit the program because of an user error

e.g. app doesn't exist on the given Developer Account
     or invalid user credentials
     or scan tests fail

This will show the error message, but doesn’t show the full

stack trace

Basically this should be used when you actively catch the error and want to show a nice error message to the user

Raises:

  • (UIError.new(show_github_issues: options[:show_github_issues]))


169
170
171
172
# File 'lib/u3d_core/ui/interface.rb', line 169

def user_error!(error_message, options = {})
  options = { show_github_issues: false }.merge(options)
  raise UIError.new(show_github_issues: options[:show_github_issues]), error_message.to_s
end

#verbose(_message) ⇒ Object

Level Verbose: Print out additional information for the

users that are interested. Will only be printed when
$verbose = true

By default those messages are shown in white


94
95
96
# File 'lib/u3d_core/ui/interface.rb', line 94

def verbose(_message)
  not_implemented(__method__)
end