Class: Metior::Report
- Defined in:
- lib/metior/report.rb,
lib/metior/report/view.rb,
lib/metior/report/view_helper.rb,
reports/default.rb
Overview
This code is free software; you can redistribute it and/or modify it under the terms of the new BSD License.
Copyright (c) 2011, Sebastian Staudt
Direct Known Subclasses
Defined Under Namespace
Modules: ViewHelper Classes: Default, View
Constant Summary collapse
- REPORTS_PATH =
The path where the reports bundled with Metior live
File. File.join File.dirname(__FILE__), '..', '..', 'reports'
Instance Attribute Summary collapse
-
#range ⇒ String, Range
readonly
Returns the range of commits that should be analyzed by this report.
-
#repository ⇒ Repository
readonly
Returns the repository that should be analyzed by this report.
Class Method Summary collapse
-
.create(name, repository, range = repository.vcs::DEFAULT_BRANCH) ⇒ Object
Create a new report instance for the given report name, repository and commit range.
-
.name ⇒ String
Returns the name of this report.
-
.path ⇒ String
Returns the file system path this report resides in.
-
.template_path ⇒ String
Returns the file system path this report's templates reside in.
-
.view_path ⇒ String
Returns the file system path this report's views reside in.
-
.views ⇒ Object
Returns the symbolic names of the main views this report consists of.
Instance Method Summary collapse
-
#copy_assets(target_dir) ⇒ Object
private
Copies the assets coming with this report to the given target directory.
-
#generate(target_dir) ⇒ Object
Generates this report's output into the given target directory.
-
#initialize(repository, range = repository.vcs::DEFAULT_BRANCH) ⇒ Report
constructor
Creates a new report for the given repository and commit range.
Constructor Details
#initialize(repository, range = repository.vcs::DEFAULT_BRANCH) ⇒ Report
Creates a new report for the given repository and commit range
87 88 89 90 |
# File 'lib/metior/report.rb', line 87 def initialize(repository, range = repository.vcs::DEFAULT_BRANCH) @range = range @repository = repository end |
Instance Attribute Details
#range ⇒ String, Range (readonly)
Returns the range of commits that should be analyzed by this report
28 29 30 |
# File 'lib/metior/report.rb', line 28 def range @range end |
#repository ⇒ Repository (readonly)
Returns the repository that should be analyzed by this report
33 34 35 |
# File 'lib/metior/report.rb', line 33 def repository @repository end |
Class Method Details
.create(name, repository, range = repository.vcs::DEFAULT_BRANCH) ⇒ Object
Create a new report instance for the given report name, repository and commit range
42 43 44 45 46 |
# File 'lib/metior/report.rb', line 42 def self.create(name, repository, range = repository.vcs::DEFAULT_BRANCH) require File.join(REPORTS_PATH, name.to_s) name = name.to_s.split('_').map { |n| n.capitalize }.join('') const_get(name.to_sym).new(repository, range) end |
.name ⇒ String
Returns the name of this report
51 52 53 |
# File 'lib/metior/report.rb', line 51 def self.name class_variable_get(:@@name).to_s end |
.path ⇒ String
Returns the file system path this report resides in
58 59 60 |
# File 'lib/metior/report.rb', line 58 def self.path File.join REPORTS_PATH, name end |
.template_path ⇒ String
Returns the file system path this report's templates reside in
65 66 67 |
# File 'lib/metior/report.rb', line 65 def self.template_path File.join path, 'templates' end |
.view_path ⇒ String
Returns the file system path this report's views reside in
72 73 74 |
# File 'lib/metior/report.rb', line 72 def self.view_path File.join path, 'views' end |
.views ⇒ Object
Returns the symbolic names of the main views this report consists of
79 80 81 |
# File 'lib/metior/report.rb', line 79 def self.views class_variable_get :@@views end |
Instance Method Details
#copy_assets(target_dir) ⇒ Object (private)
Copies the assets coming with this report to the given target directory
This will copy the contents of the images
, javascript
and
stylesheets
directories inside the report's path into the target
directory.
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/metior/report.rb', line 126 def copy_assets(target_dir) FileUtils.mkdir_p target_dir %w{images javascripts stylesheets}.map do |type| File.join(self.class.path, type) end.each do |src| next unless File.directory? src FileUtils.cp_r src, target_dir end end |
#generate(target_dir) ⇒ Object
Generates this report's output into the given target directory
This will generate individual HTML files for the main views of the report.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/metior/report.rb', line 98 def generate(target_dir) target_dir = File. target_dir copy_assets(target_dir) Mustache.template_path = self.class.template_path Mustache.view_path = self.class.view_path Mustache.view_namespace = self.class self.class.views.each do |view_name| file_name = File.join target_dir, view_name.to_s.downcase + '.html' begin output_file = File.open file_name, 'w' output_file.write Mustache.view_class(view_name).new(self).render ensure output_file.close end end end |