Class: Todonotes
Overview
Singleton definition for a fixme.
You can use Fixme#instance to set some global settings:
-
FiXme#log2file Define log file
-
FiXme#logger adapt level, outputter …
-
FiXme#codeline get Hash with counter per ToDo-locations.
-
FiXme#overview get overview text with ToDo-locations.
Constant Summary collapse
- VERSION =
'0.1.0'
Instance Attribute Summary collapse
-
#codeline ⇒ Object
readonly
Direct access to the codeline list.
-
#logger ⇒ Object
readonly
Get logger to define alternative outputters…
Class Method Summary collapse
-
.print_stats ⇒ Object
See Todonotes#overview.
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.
-
#log_todo(key, type, text, res) ⇒ Object
Report the ToDo/FixMe and count occurence.
-
#overview ⇒ Object
Return a text to be printed puts Todonotes.instance.todo_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.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/todonotes.rb', line 67 def initialize() # @codeline is a Hash with Filename and codeline (key). Value is the number of calls. @codeline = Hash.new(0) @logger = Log4r::Logger.new('ToDo') @logger.outputters = Log4r::StdoutOutputter.new('ToDo', :level => Log4r::ALL, :formatter => Log4r::FixmeFormatter ) #~ @logger.trace = true end |
Instance Attribute Details
#codeline ⇒ Object (readonly)
Direct access to the codeline list. See also #todo_overview
93 94 95 |
# File 'lib/todonotes.rb', line 93 def codeline @codeline end |
#logger ⇒ Object (readonly)
Get logger to define alternative outputters…
78 79 80 |
# File 'lib/todonotes.rb', line 78 def logger @logger end |
Class Method Details
.print_stats ⇒ Object
See Todonotes#overview
156 157 158 |
# File 'lib/todonotes.rb', line 156 def print_stats() puts Todonotes.instance.overview() 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
84 85 86 87 88 89 90 91 |
# File 'lib/todonotes.rb', line 84 def log2file(filename = File.basename($0) + '.todo', level = Log4r::ALL) @logger.add( Log4r::FileOutputter.new('ToDo', :filename => filename, :level => level, :formatter => Log4r::FixmeFormatter )) end |
#log_todo(key, type, text, res) ⇒ Object
Report the ToDo/FixMe and count occurence.
The first occurence is reported as a warning, next occurences are informations.
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/todonotes.rb', line 117 def log_todo( key, type, text, res ) @codeline[key] += 1 if @codeline[key] == 1 #First occurence? @logger.warn([type, "#{key} #{text} (temporary: #{res.inspect})"]) else #Erste auftauchen @logger.info([type, "#{key}(#{@codeline[key]}) #{text} (temporary: #{res.inspect})"]) end end |
#overview ⇒ Object
Return a text to be printed
puts Todonotes.instance.todo_overview()
Used from Todonotes.print_stats
Example:
List of ToDos/FixMes:
fixme.rb:195: 1 call
fixme.rb:198: 2 calls
fixme.rb:199: 1 call
fixme.rb:200: 1 call
140 141 142 143 144 145 146 147 |
# File 'lib/todonotes.rb', line 140 def overview( ) txt = [] txt << "List of ToDos/FixMes:" @codeline.each do |key, | txt << "%s: %4i call%s" % [ key, , > 1 ? 's': '' ] end txt.join("\n") end |
#todo(comment, type = :ToDo, &block) ⇒ Object
Report a FixMe or a ToDo.
The comment is logged, the block is evaluated to get a temporary result.
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/todonotes.rb', line 100 def todo( comment, type = :ToDo, &block) res = nil key = caller[1].split(':in').first if block_given? res = yield self res end log_todo(key, type, comment, res) #~ @logger.debug("Return #{res.inspect} instead") if @logger.debug? res end |