Module: Itamae::Logger::Helper

Defined in:
lib/itamae/logger.rb

Instance Method Summary collapse

Instance Method Details

#color(code, &block) ⇒ Object



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

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

#indentObject



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

def indent
  self.indent_depth += 1
end

#indent_depthObject



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

def indent_depth
  @indent_depth ||= 0
end

#indent_depth=(val) ⇒ Object



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

def indent_depth=(val)
  @indent_depth = val
end

#outdentObject



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

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

#with_indentObject



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

def with_indent
  indent
  yield
ensure
  outdent
end

#with_indent_if(condition, &block) ⇒ Object



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

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