Class: ReportAssembler
Constant Summary collapse
Instance Attribute Summary collapse
-
#runners ⇒ Object
Returns the value of attribute runners.
Instance Method Summary collapse
- #already_tested?(runner) ⇒ Boolean
- #cull_old_reports(project_name) ⇒ Object
- #flush_build_progress(runner) ⇒ Object
- #generate ⇒ Object
- #get_project_reports ⇒ Object
- #init_project_reports ⇒ Object
-
#initialize(projects_directory, output_directory) ⇒ ReportAssembler
constructor
A new instance of ReportAssembler.
- #update_currently_building(runner) ⇒ Object
- #update_index ⇒ Object
- #update_project(runner) ⇒ Object
- #update_projects ⇒ Object
Constructor Details
#initialize(projects_directory, output_directory) ⇒ ReportAssembler
Returns a new instance of ReportAssembler.
7 8 9 10 11 12 |
# File 'lib/crazy_ivan/report_assembler.rb', line 7 def initialize(projects_directory, output_directory) @runners = [] @projects = {} @projects_directory = projects_directory @output_directory = File.(output_directory, projects_directory) end |
Instance Attribute Details
#runners ⇒ Object
Returns the value of attribute runners.
5 6 7 |
# File 'lib/crazy_ivan/report_assembler.rb', line 5 def runners @runners end |
Instance Method Details
#already_tested?(runner) ⇒ Boolean
109 110 111 112 113 114 115 116 117 |
# File 'lib/crazy_ivan/report_assembler.rb', line 109 def already_tested?(runner) project_path = File.join(@output_directory, runner.project_name) Dir.chdir(project_path) do version = runner.results[:version][:output] tested_versions = @projects[runner.project_name].map {|r| r['version']['output'] } tested_versions.include?(version) end end |
#cull_old_reports(project_name) ⇒ Object
132 133 134 |
# File 'lib/crazy_ivan/report_assembler.rb', line 132 def cull_old_reports(project_name) @projects[project_name].shift if @projects[project_name].size > MAXIMUM_RECENTS end |
#flush_build_progress(runner) ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/crazy_ivan/report_assembler.rb', line 136 def flush_build_progress(runner) project_results_path = File.join(@output_directory, runner.project_name) Dir.chdir(project_results_path) do File.open("currently_building.json", 'w+') do |f| f.puts({}.to_json) end end end |
#generate ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/crazy_ivan/report_assembler.rb', line 14 def generate Dir.chdir(@projects_directory) do Dir['*'].each do |dir| if File.directory?(dir) runners << TestRunner.new(File.join(@projects_directory, dir), self) end end end Dir.chdir(@output_directory) do # Write out the index.html file update_index # Write out the projects.json file and the reports.json in each update_projects init_project_reports get_project_reports runners.each do |runner| # REFACTOR to run this block in multiple threads to have multi-project testing # Write the first version of the report with just the start time to currently_building.json runner.start! update_currently_building(runner) # Update the report in currently_building.json with the update output and error runner.update! update_currently_building(runner) # Update the report in currently_building.json with the version output and error runner.version! update_currently_building(runner) if already_tested?(runner) Syslog.debug("Already tested #{runner.project_name} version #{runner.results[:version][:output]} - skipping test") else # update_project will be called from within the runner to stream the test output runner.test! update_project(runner) end flush_build_progress(runner) end end end |
#get_project_reports ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/crazy_ivan/report_assembler.rb', line 89 def get_project_reports projects = @runners.map {|r| r.project_name } Dir.chdir(@output_directory) do projects.each do |project_name| reports = JSON.parse(File.read(File.('reports.json', project_name))) @projects[project_name] = reports end end end |
#init_project_reports ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/crazy_ivan/report_assembler.rb', line 74 def init_project_reports projects = @runners.map {|r| r.project_name } projects.each do |project_name| FileUtils.mkdir_p(project_name) Dir.chdir(project_name) do if !File.exists?('reports.json') File.open('reports.json', 'w+') do |f| f.puts [].to_json end end end end end |
#update_currently_building(runner) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/crazy_ivan/report_assembler.rb', line 100 def update_currently_building(runner) project_path = File.(runner.project_name, @output_directory) Dir.chdir(project_path) do File.open('currently_building.json', 'w+') do |f| f.puts runner.results.to_json end end end |
#update_index ⇒ Object
60 61 62 63 64 |
# File 'lib/crazy_ivan/report_assembler.rb', line 60 def update_index FileUtils.cp(File.("index.html", TEMPLATES_PATH), 'index.html') FileUtils.mkdir_p('javascript') FileUtils.cp(File.("date.js", File.join(TEMPLATES_PATH, 'javascript')), 'javascript/date.js') end |
#update_project(runner) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/crazy_ivan/report_assembler.rb', line 119 def update_project(runner) project_path = File.(runner.project_name, @output_directory) @projects[runner.project_name] << runner.results cull_old_reports(runner.project_name) Dir.chdir(project_path) do File.open("reports.json", 'w+') do |f| f.puts @projects[runner.project_name].to_json end end end |