Class: NoteTracker::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/note_tracker/tracker.rb

Instance Method Summary collapse

Constructor Details

#initialize(token, project, options = {}) ⇒ Tracker

Returns a new instance of Tracker.



6
7
8
9
10
11
# File 'lib/note_tracker/tracker.rb', line 6

def initialize(token, project, options = {})
  @token = token
  @project = project
  @tags_to_track = options.fetch(:tags) { "OPTIMIZE|FIXME|TODO" }
  @directories_to_track = options.fetch(:directories) { %w(.) }
end

Instance Method Details

#performObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/note_tracker/tracker.rb', line 13

def perform
  results_annotation_extractor.each do |file, annotations|
    temp_file = Tempfile.new('foo')

    File.open(file, 'r') do |file|
      file.each_line do |line|
        annotation = annotations.detect { |annotation| annotation.line == file.lineno }
        if annotation && !annotation.trackered?
          story_id = create_story(annotation).id
          line.gsub!("#{annotation.tag}","[##{story_id}] #{annotation.tag}")
        end
        temp_file.puts line
      end
    end

    temp_file.close
    FileUtils.mv(temp_file.path, file)
  end
end