Module: XCCache::UI

Extended by:
Config::Mixin
Defined in:
lib/xccache/core/log.rb

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Config::Mixin

config

Class Attribute Details

.indentObject

Returns the value of attribute indent.



10
11
12
# File 'lib/xccache/core/log.rb', line 10

def indent
  @indent
end

Class Method Details

.error(message) ⇒ Object



42
43
44
# File 'lib/xccache/core/log.rb', line 42

def error(message)
  UI.puts("[ERROR] #{message}".red)
end

.error!(message) ⇒ Object

Raises:



46
47
48
49
# File 'lib/xccache/core/log.rb', line 46

def error!(message)
  error(message)
  raise GeneralError, message
end

.info(message) ⇒ Object



34
35
36
# File 'lib/xccache/core/log.rb', line 34

def info(message)
  UI.puts(message)
end

.message(message) ⇒ Object



30
31
32
# File 'lib/xccache/core/log.rb', line 30

def message(message)
  UI.puts(message) if config.verbose?
end

.puts(message) ⇒ Object



51
52
53
# File 'lib/xccache/core/log.rb', line 51

def puts(message)
  $stdout.puts("#{' ' * self.indent}#{message}")
end

.section(title, timing: false) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/xccache/core/log.rb', line 12

def section(title, timing: false)
  start = Time.new if timing
  UI.puts(title)
  self.indent += 2
  res = yield if block_given?
  self.indent -= 2
  if timing
    duration = (Time.new - start).to_i
    duration = if duration < 60 then "#{duration}s"
               elsif duration < 60 * 60 then "#{duration / 60}m"
               else
                 "#{duration / 3600}h"
               end
    UI.puts("-> Finished: #{title.dark} (#{duration})")
  end
  res
end

.warn(message) ⇒ Object



38
39
40
# File 'lib/xccache/core/log.rb', line 38

def warn(message)
  UI.puts(message.yellow)
end