Class: RubiGen::SimpleLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/rubigen/simple_logger.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out = $stdout) ⇒ SimpleLogger

Returns a new instance of SimpleLogger.



6
7
8
9
10
# File 'lib/rubigen/simple_logger.rb', line 6

def initialize(out = $stdout)
  @out = out
  @quiet = false
  @level = 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



40
41
42
# File 'lib/rubigen/simple_logger.rb', line 40

def method_missing(method, *args, &block)
  log(method.to_s, args.first, &block)
end

Instance Attribute Details

#outObject (readonly)

Returns the value of attribute out.



3
4
5
# File 'lib/rubigen/simple_logger.rb', line 3

def out
  @out
end

#quietObject

Returns the value of attribute quiet.



4
5
6
# File 'lib/rubigen/simple_logger.rb', line 4

def quiet
  @quiet
end

Instance Method Details

#indent(&block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/rubigen/simple_logger.rb', line 17

def indent(&block)
  @level += 1
  if block_given?
    begin
      block.call
    ensure
      outdent
    end
  end
end

#log(status, message, &block) ⇒ Object



12
13
14
15
# File 'lib/rubigen/simple_logger.rb', line 12

def log(status, message, &block)
  @out.print("%12s  %s%s\n" % [status, '  ' * @level, message]) unless quiet
  indent(&block) if block_given?
end

#outdentObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/rubigen/simple_logger.rb', line 28

def outdent
  @level -= 1
  if block_given?
    begin
      block.call
    ensure
      indent
    end
  end
end