Class: Expressir::Coverage::Report
- Inherits:
-
Object
- Object
- Expressir::Coverage::Report
- Defined in:
- lib/expressir/coverage.rb
Overview
Represents a documentation coverage report for EXPRESS schemas
Instance Attribute Summary collapse
-
#documented_entities ⇒ Object
readonly
Returns the value of attribute documented_entities.
-
#ignored_files ⇒ Object
readonly
Returns the value of attribute ignored_files.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
-
#schema_reports ⇒ Object
readonly
Returns the value of attribute schema_reports.
-
#total_entities ⇒ Object
readonly
Returns the value of attribute total_entities.
-
#undocumented_entities ⇒ Object
readonly
Returns the value of attribute undocumented_entities.
Class Method Summary collapse
-
.from_file(path, skip_types = [], ignored_files = {}) ⇒ Report
Create a report from a schema file.
-
.from_repository(repository, skip_types = [], ignored_files = {}) ⇒ Report
Create a report from a repository.
Instance Method Summary collapse
-
#coverage_percentage ⇒ Float
Calculate the overall coverage percentage.
-
#directory_reports ⇒ Array<Hash>
Get directory-level reports.
-
#file_reports ⇒ Array<Hash>
Get file-level reports.
-
#ignored_file_reports ⇒ Array<Hash>
Get ignored file reports.
-
#initialize(repository, skip_types = [], ignored_files = {}) ⇒ Report
constructor
Initialize a coverage report.
-
#to_h ⇒ Hash
Convert report to a hash representation.
Constructor Details
#initialize(repository, skip_types = [], ignored_files = {}) ⇒ Report
Initialize a coverage report
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/expressir/coverage.rb', line 68 def initialize(repository, skip_types = [], ignored_files = {}) @repository = repository @skip_types = skip_types @ignored_files = ignored_files @schema_reports = [] @total_entities = [] @documented_entities = [] @undocumented_entities = [] process_repository end |
Instance Attribute Details
#documented_entities ⇒ Object (readonly)
Returns the value of attribute documented_entities.
61 62 63 |
# File 'lib/expressir/coverage.rb', line 61 def documented_entities @documented_entities end |
#ignored_files ⇒ Object (readonly)
Returns the value of attribute ignored_files.
61 62 63 |
# File 'lib/expressir/coverage.rb', line 61 def ignored_files @ignored_files end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
61 62 63 |
# File 'lib/expressir/coverage.rb', line 61 def repository @repository end |
#schema_reports ⇒ Object (readonly)
Returns the value of attribute schema_reports.
61 62 63 |
# File 'lib/expressir/coverage.rb', line 61 def schema_reports @schema_reports end |
#total_entities ⇒ Object (readonly)
Returns the value of attribute total_entities.
61 62 63 |
# File 'lib/expressir/coverage.rb', line 61 def total_entities @total_entities end |
#undocumented_entities ⇒ Object (readonly)
Returns the value of attribute undocumented_entities.
61 62 63 |
# File 'lib/expressir/coverage.rb', line 61 def undocumented_entities @undocumented_entities end |
Class Method Details
.from_file(path, skip_types = [], ignored_files = {}) ⇒ Report
Create a report from a schema file
94 95 96 97 |
# File 'lib/expressir/coverage.rb', line 94 def self.from_file(path, skip_types = [], ignored_files = {}) repository = Expressir::Express::Parser.from_file(path) new(repository, skip_types, ignored_files) end |
.from_repository(repository, skip_types = [], ignored_files = {}) ⇒ Report
Create a report from a repository
85 86 87 |
# File 'lib/expressir/coverage.rb', line 85 def self.from_repository(repository, skip_types = [], ignored_files = {}) new(repository, skip_types, ignored_files) end |
Instance Method Details
#coverage_percentage ⇒ Float
Calculate the overall coverage percentage
101 102 103 104 105 |
# File 'lib/expressir/coverage.rb', line 101 def coverage_percentage return 100.0 if @total_entities.empty? (@documented_entities.size.to_f / @total_entities.size) * 100 end |
#directory_reports ⇒ Array<Hash>
Get directory-level reports
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/expressir/coverage.rb', line 168 def directory_reports # Group by directory (absolute path) by_directory = file_reports.group_by { |r| r["directory"] } # Aggregate stats for each directory by_directory.map do |directory, reports| # Convert directory to relative path relative_directory = begin Pathname.new(directory).relative_path_from(Pathname.pwd).to_s rescue ArgumentError # If paths are on different drives or otherwise incompatible, # fall back to the absolute path directory end total = reports.sum { |r| r["total"] } documented = reports.sum { |r| r["documented"] } coverage = total.positive? ? (documented.to_f / total) * 100 : 100.0 { "directory" => relative_directory, "total" => total, "documented" => documented, "undocumented" => total - documented, "coverage" => coverage, "files" => reports.size, } end end |
#file_reports ⇒ Array<Hash>
Get file-level reports
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/expressir/coverage.rb', line 109 def file_reports @schema_reports.map do |report| absolute_path = report[:schema].file relative_path = begin Pathname.new(absolute_path).relative_path_from(Pathname.pwd).to_s rescue ArgumentError # If paths are on different drives or otherwise incompatible, # fall back to the absolute path absolute_path end file_report = { "file" => relative_path, "file_basename" => File.basename(absolute_path), "directory" => File.dirname(absolute_path), "total" => report[:total].size, "documented" => report[:documented].size, "undocumented" => report[:undocumented], "coverage" => report[:coverage], "ignored" => report[:ignored] || false, } # Add matched pattern for ignored files if report[:ignored] && report[:matched_pattern] file_report["matched_pattern"] = report[:matched_pattern] end file_report end end |
#ignored_file_reports ⇒ Array<Hash>
Get ignored file reports
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/expressir/coverage.rb', line 142 def ignored_file_reports @schema_reports.select { |report| report[:ignored] }.map do |report| absolute_path = report[:schema].file relative_path = begin Pathname.new(absolute_path).relative_path_from(Pathname.pwd).to_s rescue ArgumentError # If paths are on different drives or otherwise incompatible, # fall back to the absolute path absolute_path end { "file" => relative_path, "file_basename" => File.basename(absolute_path), "directory" => File.dirname(absolute_path), "total" => report[:total].size, "documented" => report[:documented].size, "undocumented" => report[:undocumented], "coverage" => report[:coverage], "matched_pattern" => report[:matched_pattern], } end end |
#to_h ⇒ Hash
Convert report to a hash representation
200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/expressir/coverage.rb', line 200 def to_h { "overall" => { "total" => @total_entities.size, "documented" => @documented_entities.size, "undocumented" => @undocumented_entities.size, "coverage" => coverage_percentage, }, "directories" => directory_reports, "files" => file_reports, } end |