Class: Todonotes::Todo

Inherits:
Object
  • Object
show all
Defined in:
lib/todonotes/todo.rb

Overview

Report the ToDo/FixMe and count occurence.

The first occurence is reported as a warning, next occurences are informations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(codeline, type, comment, logger, &block) ⇒ Todo

Returns a new instance of Todo.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/todonotes/todo.rb', line 14

def initialize(codeline, type, comment, logger, &block)
  @logger = logger
  @count = 1
  @codeline = codeline
  @type = type
  @shortdescription = comment      
  #Build result
  @result = yield if block_given?
  
  @logger.warn([@type, "#{@codeline} #{@shortdescription} (temporary: #{@result.inspect})"])

end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



29
30
31
# File 'lib/todonotes/todo.rb', line 29

def count
  @count
end

#resultObject (readonly)

Temporary result of the Todo. This result should become a ‘real’ value



27
28
29
# File 'lib/todonotes/todo.rb', line 27

def result
  @result
end

#short_descriptionObject (readonly)

Returns the value of attribute short_description.



28
29
30
# File 'lib/todonotes/todo.rb', line 28

def short_description
  @short_description
end

Instance Method Details

#callObject

Todo/Fixme is called again



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

def call()
  @logger.info([@type, "#{@codeline}(#{@count}) #{@shortdescription} (temporary: #{@result.inspect})"])
  @count += 1
end

#infoline(settings) ⇒ Object

Return a single line with status of the todo.

Depending on with_type you get also the type (ToDo/FixMe)



47
48
49
50
51
52
53
54
55
56
# File 'lib/todonotes/todo.rb', line 47

def infoline(settings)
  res = @codeline.dup
  res << " (%-5s)" % @type if settings.include?(:with_type)
  res << ": %4i call%s" % [ 
        @count, @count > 1 ? 's': ''  
    ]
  res << " (%s)" % @shortdescription if settings.include?(:with_shortdescription)
  res << " = '#{@result.inspect}'" if settings.include?(:with_result)
  res
end

#to_sObject



39
40
41
# File 'lib/todonotes/todo.rb', line 39

def to_s()
  "#{@type}: #{@codeline}"  
end