Class: Rails::Generator::SimpleLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_generator/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.



7
8
9
10
11
# File 'lib/rails_generator/simple_logger.rb', line 7

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)



41
42
43
# File 'lib/rails_generator/simple_logger.rb', line 41

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.



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

def out
  @out
end

#quietObject

Returns the value of attribute quiet.



5
6
7
# File 'lib/rails_generator/simple_logger.rb', line 5

def quiet
  @quiet
end

Instance Method Details

#indent(&block) ⇒ Object



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

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

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



13
14
15
16
# File 'lib/rails_generator/simple_logger.rb', line 13

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

#outdentObject



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

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