Module: Itamae::Logger::Helper

Defined in:
lib/itamae/logger.rb

Instance Method Summary collapse

Instance Method Details

#color(code, &block) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/itamae/logger.rb', line 39

def color(code, &block)
  if self.formatter.respond_to?(:color)
    self.formatter.color(code, &block)
  else
    block.call
  end
end

#indentObject



22
23
24
# File 'lib/itamae/logger.rb', line 22

def indent
  self.indent_depth += 1
end

#indent_depthObject



31
32
33
# File 'lib/itamae/logger.rb', line 31

def indent_depth
  @indent_depth ||= 0
end

#indent_depth=(val) ⇒ Object



35
36
37
# File 'lib/itamae/logger.rb', line 35

def indent_depth=(val)
  @indent_depth = val
end

#outdentObject



26
27
28
29
# File 'lib/itamae/logger.rb', line 26

def outdent
  self.indent_depth -= 1
  self.indent_depth = 0 if self.indent_depth < 0
end

#with_indentObject



7
8
9
10
11
12
# File 'lib/itamae/logger.rb', line 7

def with_indent
  indent
  yield
ensure
  outdent
end

#with_indent_if(condition, &block) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/itamae/logger.rb', line 14

def with_indent_if(condition, &block)
  if condition
    with_indent(&block)
  else
    block.call
  end
end