Module: Dapp::Dapp::Logging::Process

Included in:
Dapp::Dapp
Defined in:
lib/dapp/dapp/logging/process.rb

Constant Summary collapse

DEFAULT_TERMINAL_WIDTH =
120
DEFAULT_STYLE =
{
  message: :step,
  process: :secondary,
  status:  :secondary,
  success: :success,
  failed:  :warning,
  time:    :default
}.freeze

Instance Method Summary collapse

Instance Method Details

#log_process(message, process: nil, short: false, quiet: false, style: {}, status: {}, &blk) ⇒ Object

rubocop:disable Metrics/ParameterLists



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dapp/dapp/logging/process.rb', line 28

def log_process(message, process: nil, short: false, quiet: false, style: {}, status: {}, &blk)
  style[:message] ||= DEFAULT_STYLE[:message]
  style[:process] ||= DEFAULT_STYLE[:process]
  style[:failed] ||= DEFAULT_STYLE[:failed]
  style[:success] ||= DEFAULT_STYLE[:success]

  status[:success] ||= t(code: 'status.success.default')
  status[:failed] ||= t(code: 'status.failed.default')

  if quiet
    log_process_quiet(message.to_s, style: style, status: status, &blk)
  elsif short
    log_process_short(message.to_s, style: style, status: status, &blk)
  else
    process ||= t(code: 'status.process.default')
    log_process_verbose(message.to_s, process: process, style: style, status: status, &blk)
  end
end

#log_secondary_process(message, **kwargs, &blk) ⇒ Object

rubocop:enable Metrics/ParameterLists



48
49
50
# File 'lib/dapp/dapp/logging/process.rb', line 48

def log_secondary_process(message, **kwargs, &blk)
  log_process(message, **kwargs.merge(style: { message: :secondary, success: :secondary }), &blk)
end

#log_state(message, state:, styles: {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dapp/dapp/logging/process.rb', line 15

def log_state(message, state:, styles: {})
  styles[:message] ||= DEFAULT_STYLE[:message]
  styles[:status] ||= DEFAULT_STYLE[:status]

  message = slice(message)
  state   = rjust(state, message)
  formatted_message = paint_string(message, styles[:message])
  formatted_status  = paint_string(state, styles[:status])

  log "#{formatted_message}#{formatted_status}"
end