class TodosExport::Main

Attributes

exportables[RW]
files[RW]
target[RW]

Public Class Methods

new(target) click to toggle source
# File lib/todos_export.rb, line 17
def initialize(target)
  self.target = target
  self.exportables = []
end

Public Instance Methods

delete_exportable(file, line) click to toggle source
# File lib/todos_export.rb, line 89
def delete_exportable(file, line)
  lines = File.readlines(file)
  lines.delete_at(line - 1)

  File.open(file, "w") do |f|
    lines.each { |l| f.puts(l) }
  end

  self.find_exportables
end
delete_exportables() click to toggle source
# File lib/todos_export.rb, line 100
def delete_exportables
  while !self.exportables.empty? do
    self.delete_exportable(self.exportables[0][:file], self.exportables[0][:line])
    self.find_exportables
  end
end
execute() click to toggle source
# File lib/todos_export.rb, line 107
def execute
  self.find_exportables

  say("Found #{self.exportable_todos.size} TODO's, " \
    "#{self.exportable_fixmes.size} FIXME's and " \
    "#{self.exportable_bugs.size} BUG's" \
    " in #{self.exportables.map { |x| x[:file] }.uniq.size } of #{exportables.map { |x| x[:file] }.size } files searched.")
  say("\n")

  choose do |menu|
    menu.prompt = "Export to: "
    menu.choice('STDOUT') { TodosExport::StdOut.new(self).run }
    menu.choice('Github Issues') { TodosExport::GithubIssues.new(self).run }
  end
end
exportable_bugs() click to toggle source
# File lib/todos_export.rb, line 85
def exportable_bugs
  self.exportables.select { |x| x[:type] == 'BUG' }
end
exportable_fixmes() click to toggle source
# File lib/todos_export.rb, line 81
def exportable_fixmes
  self.exportables.select { |x| x[:type] == 'FIXME' }
end
exportable_todos() click to toggle source
# File lib/todos_export.rb, line 77
def exportable_todos
  self.exportables.select { |x| x[:type] == 'TODO' }
end
find_exportables() click to toggle source
# File lib/todos_export.rb, line 34
def find_exportables
  self.find_files
  @exportables = []

  self.files.each do |file|
    File.open(file) do |f|
      f.each_with_index do |line, number|
        search = line.scan(/((?:#)(?:| )(TODO|FIXME|BUG):?(.*)$)/i)
        if !search.empty?
          line = number + 1

          self.exportables << {
            :type => search[0][1].upcase,
            :content => search[0][2].strip,
            :original_content => search[0][0],
            :file => file.gsub(/^(.\/)/, ''),
            :original_file => file,
            :line => line,
            :line_peek => File.readlines(file)[line].strip
          }
        end
      end
    end
  end
end
find_files() click to toggle source
# File lib/todos_export.rb, line 22
def find_files
  if File.file?(self.target)
    self.files = [self.target]
  elsif File.directory?(self.target)
    self.files = Dir.glob(File.join(self.target, "**", "*.rb"))
  else
    abort "#{target} does not exist."
  end

  return self.files
end
git_directory?() click to toggle source
# File lib/todos_export.rb, line 60
def git_directory?
  begin
    Rugged::Repository.new(self.target)
    return true
  rescue
    return false
  end
end
git_head_sha() click to toggle source
# File lib/todos_export.rb, line 69
def git_head_sha
  if git_directory?
    Rugged::Repository.new(self.target).head.target.oid
  else
    nil
  end
end