Class: ChefSpec::CoverageReports
- Inherits:
-
Object
- Object
- ChefSpec::CoverageReports
- Includes:
- Singleton
- Defined in:
- lib/chefspec/coveragereports/version.rb,
lib/chefspec/coveragereports.rb
Overview
This defines the version of the gem
Defined Under Namespace
Modules: Version
Instance Attribute Summary collapse
-
#reports ⇒ Object
readonly
Returns the value of attribute reports.
Class Method Summary collapse
Instance Method Summary collapse
- #add(type, output_file) ⇒ Object
- #add_custom(template, output_file) ⇒ Object
- #clear_reports ⇒ Object
- #delete(type) ⇒ Object
- #generate_reports(data) ⇒ Object
-
#initialize ⇒ CoverageReports
constructor
A new instance of CoverageReports.
Constructor Details
#initialize ⇒ CoverageReports
24 25 26 |
# File 'lib/chefspec/coveragereports.rb', line 24 def initialize @reports = {} end |
Instance Attribute Details
#reports ⇒ Object (readonly)
Returns the value of attribute reports.
22 23 24 |
# File 'lib/chefspec/coveragereports.rb', line 22 def reports @reports end |
Class Method Details
.method_added(name) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/chefspec/coveragereports.rb', line 8 def method_added(name) # Only delegate public methods if method_defined?(name) instance_eval " def \#{name}(*args, &block)\n instance.public_send(:\#{name}, *args, &block)\n end\n EOH\n end\nend\n", __FILE__, __LINE__ + 1 |
Instance Method Details
#add(type, output_file) ⇒ Object
28 29 30 |
# File 'lib/chefspec/coveragereports.rb', line 28 def add(type, output_file) reports[root.join('templates', "#{type}.erb")] = output_file end |
#add_custom(template, output_file) ⇒ Object
32 33 34 |
# File 'lib/chefspec/coveragereports.rb', line 32 def add_custom(template, output_file) reports[template] = output_file end |
#clear_reports ⇒ Object
36 37 38 |
# File 'lib/chefspec/coveragereports.rb', line 36 def clear_reports @reports = {} end |
#delete(type) ⇒ Object
40 41 42 |
# File 'lib/chefspec/coveragereports.rb', line 40 def delete(type) reports[type] = nil end |
#generate_reports(data) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/chefspec/coveragereports.rb', line 44 def generate_reports(data) @coverage = {} @coverage['raw'] = data @coverage['coverage'] = process_report_data(data) reports.each do |template, output_file| erb = Erubis::Eruby.new(File.read(template)) # Create the output directory if it doesnt exist dirname = File.dirname(output_file) FileUtils.mkdir_p(dirname) unless File.directory?(dirname) File.open(output_file, 'w') { |f| f.write(erb.evaluate(@coverage)) } end end |