class Todonotes::Todonotes

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

end

Attributes

codelines[R]

Direct access to the codelines list. See also overview Accessible via Todonotes::Todonotes.instance.codelines()

logger[R]

Get logger to define alternative outputters…

raise_fixme[W]
raise_todo[W]

Public Class Methods

new() click to toggle source

Define the singleton-instance.

end

# 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
  @raise_todo = false
  @raise_fixme = false

end

Public Instance Methods

log2file(filename = File.basename($0) + '.todo', level = Log4r::ALL) click to toggle source

Write the todo's in a logging file.

Default filename is $0.todo

end

# File lib/todonotes/todonotes.rb, line 46
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 ) click to toggle source

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

end

# File lib/todonotes/todonotes.rb, line 98
def overview( *settings )
  txt = []
  txt << "List of ToDos/FixMes:"
  @codelines.each do |key, todo|
    txt << todo.infoline(settings)
  end
  txt.join("\n")
end
raise_fixme?() click to toggle source

Check if a fixme should throw an exception

# File lib/todonotes/todonotes.rb, line 39
def raise_fixme?; @raise_fixme;end
raise_todo?() click to toggle source

Check if a todo should throw an exception

# File lib/todonotes/todonotes.rb, line 37
def raise_todo?; @raise_todo; end
todo( comment, type = :ToDo, &block) click to toggle source

Report a FixMe or a ToDo. Create a Todonotes::Todo

The block is evaluated to get a temporary result.

end

# File lib/todonotes/todonotes.rb, line 63
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 &block
  else #First occurence?
    @codelines[codelinekey] = Todo.new(codeline, type, comment, @logger, &block)
  end 
  @codelines[codelinekey].result
end