Class: Rails::Generator::SimpleLogger
- Defined in:
- lib/rails_generator/simple_logger.rb
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.
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
#out ⇒ Object (readonly)
Returns the value of attribute out.
4 5 6 |
# File 'lib/rails_generator/simple_logger.rb', line 4 def out @out end |
#quiet ⇒ Object
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, , &block) @out.print("%12s %s%s\n" % [status, ' ' * @level, ]) unless quiet indent(&block) if block_given? end |
#outdent ⇒ Object
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 |