Class: DNote::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/dnote/rake/dnotetask.rb

Overview

Developmer’s Notes Rake Task

Constant Summary collapse

DEFAULT_LABELS =

Default note labels to looked for in source code.

%w(TODO FIXME OPTIMIZE DEPRECATE).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#excludeObject

Exclude paths.



24
25
26
# File 'lib/dnote/rake/dnotetask.rb', line 24

def exclude
  @exclude
end

#filesObject

File paths to search.



15
16
17
# File 'lib/dnote/rake/dnotetask.rb', line 15

def files
  @files
end

#formatsObject

Formats (xml, html, rdoc, rdoc/list and so on).



21
22
23
# File 'lib/dnote/rake/dnotetask.rb', line 21

def formats
  @formats
end

#ignoreObject

Ignore paths based on any part of pathname.



27
28
29
# File 'lib/dnote/rake/dnotetask.rb', line 27

def ignore
  @ignore
end

#labelsObject

Labels to document. Defaults are: TODO, FIXME, OPTIMIZE and DEPRECATE.



18
19
20
# File 'lib/dnote/rake/dnotetask.rb', line 18

def labels
  @labels
end

#outputObject

Output directory to save notes file. Defaults to dnote/ under the project log directory (eg. log/dnote/).



31
32
33
# File 'lib/dnote/rake/dnotetask.rb', line 31

def output
  @output
end

#titleObject

Title to use if temaplte can use it.



34
35
36
# File 'lib/dnote/rake/dnotetask.rb', line 34

def title
  @title
end

Instance Method Details

#cleanObject

Remove output files.



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/dnote/rake/dnotetask.rb', line 87

def clean
  formats.each do |format|
    if format == 'index'
      file = (output + 'index.html').to_s
    else
      ext = ::DNote::Format::EXTENSIONS[format] || format
      file = (output + "notes.#{ext}").to_s
    end
    rm(file)
    report "Removed #{output}"
  end
end

#defineObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/dnote/rake/dnotetask.rb', line 49

def define
  desc "Collect Developer's Notes"
  task 'dnote' do
    document
  end
  task 'dnote:clobber' do
    clean
  end
  task clobber: ['dnote:clobber']
end

#documentObject

Generate notes document(s).



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/dnote/rake/dnotetask.rb', line 61

def document
  abort "dnote: #{output} is not a directory" unless output.directory?

  session = ::DNote::Session.new do |s|
    s.paths   = files
    s.exclude = exclude
    s.ignore  = ignore
    s.labels  = labels
    s.title   = title
    s.output  = output
    s.dryrun  = application.options.dryrun # trial?
  end

  formats.each do |format|
    if format == 'index'
      session.format = 'html'
      session.output = File.join(output, 'index.html')
    else
      session.format = format
    end
    session.run
    report "Updated #{output.to_s.sub(Dir.pwd + '/', '')}" unless trial?
  end
end

#initObject



40
41
42
43
44
45
46
47
# File 'lib/dnote/rake/dnotetask.rb', line 40

def init
  require 'dnote'
  require 'dnote/format'
  @files   = '**/*.rb'
  @output  = 'log/dnote'
  @formats = ['index']
  @labels  = nil
end