Class: Regent::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/regent/logger.rb

Constant Summary collapse

COLORS =
%i[dim white green yellow red blue cyan clear].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output: $stdout) ⇒ Logger

Returns a new instance of Logger.



14
15
16
17
18
# File 'lib/regent/logger.rb', line 14

def initialize(output: $stdout)
  @pastel = Pastel.new
  @spinner = build_spinner(spinner_symbol, output)
  @nested_spinner = build_spinner("#{dim(" ├──")}#{spinner_symbol}", output)
end

Instance Attribute Details

#nested_spinnerObject (readonly)

Returns the value of attribute nested_spinner.



20
21
22
# File 'lib/regent/logger.rb', line 20

def nested_spinner
  @nested_spinner
end

#spinnerObject (readonly)

Returns the value of attribute spinner.



20
21
22
# File 'lib/regent/logger.rb', line 20

def spinner
  @spinner
end

Class Method Details

.warn_and_exit(message) ⇒ Object



8
9
10
11
# File 'lib/regent/logger.rb', line 8

def warn_and_exit(message)
  warn message
  exit 1
end

Instance Method Details

#error(**args) ⇒ Object



36
37
38
# File 'lib/regent/logger.rb', line 36

def error(**args)
  info(**args).error
end

#info(label:, message:, duration: nil, type: nil, meta: nil, top_level: false) ⇒ Object



22
23
24
25
26
# File 'lib/regent/logger.rb', line 22

def info(label:, message:, duration: nil, type: nil, meta: nil, top_level: false)
  current_spinner = top_level ? spinner : nested_spinner
  current_spinner.update(title: format_message(label, message, duration, type, meta))
  current_spinner
end

#start(**args) ⇒ Object



28
29
30
# File 'lib/regent/logger.rb', line 28

def start(**args)
  info(**args).auto_spin
end

#success(**args) ⇒ Object



32
33
34
# File 'lib/regent/logger.rb', line 32

def success(**args)
  info(**args).success
end