Class: Todonotes::Todonotes
- Inherits:
-
Object
- Object
- Todonotes::Todonotes
- Defined in:
- lib/todonotes/todonotes.rb
Overview
Collection of todos and fixmes.
The module Todonotes defines a ‘singleton’-like Todonotes::TODONOTES to collect all todo/fixme from Kernel.
You can set settings with
-
Todonotes::Todonotes#log2file Define log file
-
Todonotes::Todonotes#logger adapt level, outputter …
-
Todonotes::Todonotes#codelines get Hash with counter per ToDo-locations.
-
Todonotes::Todonotes#overview get overview text with ToDo-locations.
Instance Attribute Summary collapse
-
#codelines ⇒ Object
readonly
Direct access to the codelines list.
-
#logger ⇒ Object
readonly
Get logger to define alternative outputters…
Instance Method Summary collapse
-
#initialize ⇒ Todonotes
constructor
Define the singleton-instance.
-
#log2file(filename = File.basename($0) + '.todo', level = Log4r::ALL) ⇒ Object
Write the todo’s in a logging file.
-
#overview(*settings) ⇒ Object
Return a text to be printed puts Todonotes.overview() Used from Todonotes.print_stats.
-
#todo(comment, type = :ToDo, &block) ⇒ Object
Report a FixMe or a ToDo.
Constructor Details
#initialize ⇒ Todonotes
Define the singleton-instance.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/todonotes/todonotes.rb', line 19 def initialize() @codelines = Hash.new() @logger = Log4r::Logger.new('ToDo') @logger.outputters = Log4r::StdoutOutputter.new('ToDo', :level => Log4r::ALL, :formatter => FixmeFormatter ) #~ @logger.trace = true end |
Instance Attribute Details
#codelines ⇒ Object (readonly)
Direct access to the codelines list. See also #overview Accessible via Todonotes::Todonotes.instance.codelines()
46 47 48 |
# File 'lib/todonotes/todonotes.rb', line 46 def codelines @codelines end |
#logger ⇒ Object (readonly)
Get logger to define alternative outputters…
30 31 32 |
# File 'lib/todonotes/todonotes.rb', line 30 def logger @logger end |
Instance Method Details
#log2file(filename = File.basename($0) + '.todo', level = Log4r::ALL) ⇒ Object
Write the todo’s in a logging file.
Default filename is $0.todo
36 37 38 39 40 41 42 43 |
# File 'lib/todonotes/todonotes.rb', line 36 def log2file(filename = File.basename($0) + '.todo', level = Log4r::ALL) @logger.add( Log4r::FileOutputter.new('ToDo', :filename => filename, :level => level, :formatter => FixmeFormatter )) end |
#overview(*settings) ⇒ Object
Return a text to be printed
puts Todonotes.overview()
Used from Todonotes.print_stats
Example:
List of ToDos/FixMes:
todonotes.rb:230: 1 call
todonotes.rb:233: 2 calls
todonotes.rb:234: 1 call
todonotes.rb:235: 1 call
You may extend the output by parameters:
-
:with_type
-
:with_shortdescription
-
:with_result
Example :with_type:
todonotes.rb:230 (ToDo): 1 call
todonotes.rb:233 (ToDo): 2 calls
todonotes.rb:234 (FixMe): 1 call
todonotes.rb:235 (ToDo): 1 call
88 89 90 91 92 93 94 95 |
# File 'lib/todonotes/todonotes.rb', line 88 def overview( *settings ) txt = [] txt << "List of ToDos/FixMes:" @codelines.each do |key, todo| txt << todo.(settings) end txt.join("\n") end |
#todo(comment, type = :ToDo, &block) ⇒ Object
Report a FixMe or a ToDo. Create a Todonotes::Todo
The block is evaluated to get a temporary result.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/todonotes/todonotes.rb', line 53 def todo( comment, type = :ToDo, &block) codeline = caller[1].split(':in').first codelinekey = "#{codeline} (#{type})" if @codelines[codelinekey] #2nd or more calls @codelines[codelinekey].call else #First occurence? @codelines[codelinekey] = Todo.new(codeline, type, comment, @logger, &block) end @codelines[codelinekey].result end |