Module: Bwrap::Output

Overview

Declare Output module here so Bwrap::Output module is already declared for Output module classes, to avoid a circular dependency.

See output/output.rb for documentation.

Defined Under Namespace

Modules: Colors Classes: Levels, Log

Class Method Summary collapse

Class Method Details

.debug?Boolean

Returns:

  • (Boolean)

See Also:

  • #debug?


44
45
46
# File 'lib/bwrap/output/output_impl.rb', line 44

def self.debug?
  Bwrap::Output::Levels.debug?
end

.debug_output(str, raw: false, log_callback: 1) ⇒ Object

Handler used by #debug to output given string.



77
78
79
80
81
82
83
84
85
86
# File 'lib/bwrap/output/output_impl.rb', line 77

def self.debug_output str, raw: false, log_callback: 1
  return unless debug?

  if raw
    print str
  else
    out = Bwrap::Output::Levels.debug_print_formatted str, log_callback: (log_callback + 1)
  end
  Bwrap::Output::Log.puts_to_log out || str
end

.error_output(str = nil, label: :unspecified, log_callback: 1, raise_exception: false) ⇒ Object

Aborts current process.

Use this instead of Ruby’s #exit in order to filter out dummy #exit calls from the code.



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/bwrap/output/output_impl.rb', line 125

def self.error_output str = nil, label: :unspecified, log_callback: 1, raise_exception: false
  unless str.nil?
    out = Bwrap::Output::Levels.error_print_formatted str, log_callback: (log_callback + 1)
    Bwrap::Output::Log.puts_to_log out
  end

  exit_code = Bwrap::Execution::Labels.resolve_exit_code(label)
  raise str if raise_exception

  exit exit_code
end

.handle_output_options(options) ⇒ Object

Takes hash of options received from Optimist and checks output related flags.



60
61
62
# File 'lib/bwrap/output/output_impl.rb', line 60

def self.handle_output_options options
  Bwrap::Output::Levels.handle_output_options options
end

.info_output(str, raw: false, log_callback: 1) ⇒ Object

Handler used by #info to output given string.



101
102
103
104
105
106
107
108
109
110
# File 'lib/bwrap/output/output_impl.rb', line 101

def self.info_output str, raw: false, log_callback: 1
  return if quiet?

  if raw
    print str
  else
    out = Bwrap::Output::Levels.info_print_formatted str, log_callback: (log_callback + 1)
  end
  Bwrap::Output::Log.puts_to_log out || str
end

.quiet?Boolean

Returns:

  • (Boolean)

See Also:

  • #quiet?
  • #info


50
51
52
# File 'lib/bwrap/output/output_impl.rb', line 50

def self.quiet?
  Bwrap::Output::Levels.quiet?
end

.trace?Boolean

Returns:

  • (Boolean)

See Also:

  • #trace?


55
56
57
# File 'lib/bwrap/output/output_impl.rb', line 55

def self.trace?
  Bwrap::Output::Levels.trace?
end

.trace_output(str, raw: false, log_callback: 1) ⇒ Object

Handler used by #trace to output given string.



65
66
67
68
69
70
71
72
73
74
# File 'lib/bwrap/output/output_impl.rb', line 65

def self.trace_output str, raw: false, log_callback: 1
  return unless trace?

  if raw
    print str
  else
    out = Bwrap::Output::Levels.trace_print_formatted str, log_callback: (log_callback + 1)
  end
  Bwrap::Output::Log.puts_to_log out || str
end

.verb_output(str, raw: false, log_callback: 1) ⇒ Object

Handler used by #verb to output given string.



89
90
91
92
93
94
95
96
97
98
# File 'lib/bwrap/output/output_impl.rb', line 89

def self.verb_output str, raw: false, log_callback: 1
  return unless verbose?

  if raw
    print str
  else
    out = Bwrap::Output::Levels.verbose_print_formatted str, log_callback: (log_callback + 1)
  end
  Bwrap::Output::Log.puts_to_log out || str
end

.verbose?Boolean

Returns:

  • (Boolean)

See Also:

  • #verbose?


39
40
41
# File 'lib/bwrap/output/output_impl.rb', line 39

def self.verbose?
  Bwrap::Output::Levels.verbose?
end

.warn_output(str, raw: false, log_callback: 1) ⇒ Object

Handler used by #warn to output given string.



113
114
115
116
117
118
119
120
# File 'lib/bwrap/output/output_impl.rb', line 113

def self.warn_output str, raw: false, log_callback: 1
  if raw
    print str
  else
    out = Bwrap::Output::Levels.warning_print_formatted str, log_callback: (log_callback + 1)
  end
  Bwrap::Output::Log.puts_to_log out || str
end