Class: Babygitter::ReportGenerator::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/babygitter/report_generator/application.rb

Class Method Summary collapse

Class Method Details

.check_if_directory_exits(arguments) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/babygitter/report_generator/application.rb', line 56

def check_if_directory_exits(arguments)
  if !File.exists?(arguments.first)
    abort "'#{arguments.first}' does not exist."
  elsif !File.directory?(arguments.first)
    abort "'#{arguments.first}' is not a directory."
  end
end

.level_sentenceObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/babygitter/report_generator/application.rb', line 13

def level_sentence
  if Babygitter.folder_levels.size > 1
    'levels ' +
    Babygitter.folder_levels[0..-2].map do |level|
      "#{level}"
    end.join(", ") + " and #{Babygitter.folder_levels.last}"
  else
    "level #{Babygitter.folder_levels.first}"
  end
end

.prepare_file_stuctureObject



7
8
9
10
11
# File 'lib/babygitter/report_generator/application.rb', line 7

def prepare_file_stucture
  path = Babygitter.report_file_path
  FileUtils.mkdir_p "#{path}/babygitter_images" unless File.exists?("#{path}/babygitter_images")
  FileUtils.cp_r("#{Babygitter.image_assets_path}" + "/.", "#{path}/asset_images/")
end

.run!(*arguments) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/babygitter/report_generator/application.rb', line 64

def run!(*arguments)
  options = Babygitter::ReportGenerator::Options.new(arguments)

  if options[:show_help]
    $stderr.puts options.opts
    return 1
  end

  if options[:show_version_number]
    refs = open(File.join(File.dirname(__FILE__), '../../../VERSION.yml')) {|f| YAML.load(f) }
    $stdout.puts "Babygitter Version #{refs[:major]}.#{refs[:minor]}.#{refs[:patch]}"
    return 1
  end

  unless arguments.size == 1
    $stderr.puts options.opts
    return 1
  end

  begin
    check_if_directory_exits(arguments)
    repo_path = File.expand_path arguments.first
    if options[:verbose]
      verbose_output(options)
    end
    generator = Babygitter::ReportGenerator.new(repo_path, {:is_bare => options[:is_bare]}, options[:master_branch])
    prepare_file_stucture
    $stdout.puts "Begun generating report."
    generator.write_report
    $stdout.puts "Report written to #{Babygitter.report_file_path}"
    return 0
  rescue Grit::InvalidGitRepositoryError
    $stderr.puts "#{Babygitter.repo_path} is not a git repository"
    return 1
  end
end

.using_custom_files?Boolean

Displays custome files being used in gneration, if any, when verbose is on.

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/babygitter/report_generator/application.rb', line 25

def using_custom_files?
  if Babygitter.template.scan(/lib\/babygitter\/assets\/templates\/default.html.erb/).empty?
    $stdout.puts "Using custom template at #{Babygitter.template}"
  end
  
  if Babygitter.stylesheet.scan(/babygitter\/assets\/stylesheets\/default.css/).empty?
    $stdout.puts "Using custom stylesheet at #{Babygitter.stylesheet}"
  end
  
  if Babygitter.image_assets_path.scan(/lib\/babygitter\/assets\/image_assets/).empty?
    $stdout.puts "Using custom images at #{Babygitter.image_assets_path}"
  end
end

.verbose_output(options) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/babygitter/report_generator/application.rb', line 39

def verbose_output(options)
  $stdout.puts "Repo path set as #{Babygitter.repo_path}"
  $stdout.puts "Repo is bare" if options[:is_bare]
  using_custom_files?
  $stdout.puts "Using whitelist option" if Babygitter.use_whitelist
  unless Babygitter.output_graphs
    $stdout.puts "No graphs will be generated"
  else
    unless Babygitter.folder_levels.empty? || Babygitter.folder_levels == [0]
      $stdout.puts "Report will plot folder #{level_sentence}"
    else
      $stdout.puts "Report will not plot lines committed by folder levels"
    end
  end
  $stdout.puts "Report will be generated to #{Babygitter.report_file_path}"
end