Class: RubiGen::SimpleLogger
Overview
:nodoc:
Instance Attribute Summary collapse
-
#out ⇒ Object
readonly
Returns the value of attribute out.
-
#quiet ⇒ Object
Returns the value of attribute quiet.
Instance Method Summary collapse
- #indent(&block) ⇒ Object
-
#initialize(out = $stdout) ⇒ SimpleLogger
constructor
A new instance of SimpleLogger.
- #log(status, message, &block) ⇒ Object
- #outdent ⇒ Object
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
#out ⇒ Object (readonly)
Returns the value of attribute out.
3 4 5 |
# File 'lib/rubigen/simple_logger.rb', line 3 def out @out end |
#quiet ⇒ Object
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, , &block) @out.print("%12s %s%s\n" % [status, ' ' * @level, ]) unless quiet indent(&block) if block_given? end |
#outdent ⇒ Object
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 |