Class: Todonotes::Todonotes

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeTodonotes

Define the singleton-instance.



19
20
21
22
23
24
25
26
27
28
29
30
31
# 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

Instance Attribute Details

#codelinesObject (readonly)

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



56
57
58
# File 'lib/todonotes/todonotes.rb', line 56

def codelines
  @codelines
end

#loggerObject (readonly)

Get logger to define alternative outputters…



33
34
35
# File 'lib/todonotes/todonotes.rb', line 33

def logger
  @logger
end

#raise_fixme=(value) ⇒ Object (writeonly)

Sets the attribute raise_fixme

Parameters:

  • value

    the value to set the attribute raise_fixme to.



35
36
37
# File 'lib/todonotes/todonotes.rb', line 35

def raise_fixme=(value)
  @raise_fixme = value
end

#raise_todo=(value) ⇒ Object (writeonly)

Sets the attribute raise_todo

Parameters:

  • value

    the value to set the attribute raise_todo to.



34
35
36
# File 'lib/todonotes/todonotes.rb', line 34

def raise_todo=(value)
  @raise_todo = value
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



46
47
48
49
50
51
52
53
# 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) ⇒ 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


98
99
100
101
102
103
104
105
# 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?Boolean

Check if a fixme should throw an exception

Returns:

  • (Boolean)


39
# File 'lib/todonotes/todonotes.rb', line 39

def raise_fixme?; @raise_fixme;end

#raise_todo?Boolean

Check if a todo should throw an exception

Returns:

  • (Boolean)


37
# File 'lib/todonotes/todonotes.rb', line 37

def raise_todo?; @raise_todo; 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.



63
64
65
66
67
68
69
70
71
72
73
# 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