Class: SCNR::Introspector::Coverage
- Inherits:
-
Object
- Object
- SCNR::Introspector::Coverage
- Defined in:
- lib/scnr/introspector/coverage.rb,
lib/scnr/introspector/coverage/resource.rb,
lib/scnr/introspector/coverage/resource/line.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#resources ⇒ Hash<String, Resource>
readonly
All in-scope web application resources, per path.
- #scope ⇒ Scope
Class Method Summary collapse
-
.enable ⇒ Object
Enables coverage tracking for all subsequently required source files.
-
.enabled? ⇒ Bool
‘true` if coverage has been #enabled, `false` otherwise.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #hash ⇒ Object
- #import_native(coverage) ⇒ Object
-
#initialize(options = {}) ⇒ Coverage
constructor
A new instance of Coverage.
-
#percentage ⇒ Float
Percentage of coverage for all application resources which are within scope.
- #retrieve_results ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Coverage
Returns a new instance of Coverage.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/scnr/introspector/coverage.rb', line 44 def initialize( = {} ) = .dup if (scope = .delete(:scope)).is_a? Scope @scope = scope elsif scope.is_a? Hash @scope = Scope.new( scope ) elsif scope.nil? @scope = Scope.new else fail Scope::Error::Invalid end @resources = {} end |
Instance Attribute Details
#resources ⇒ Hash<String, Resource> (readonly)
Returns All in-scope web application resources, per path.
34 35 36 |
# File 'lib/scnr/introspector/coverage.rb', line 34 def resources @resources end |
Class Method Details
.enable ⇒ Object
Note:
Enabling scan coverage may cause segfaults depending on interpreter version and web application type.
Enables coverage tracking for all subsequently required source files.
14 15 16 17 |
# File 'lib/scnr/introspector/coverage.rb', line 14 def enable ::Coverage.start @enabled = true end |
.enabled? ⇒ Bool
Returns ‘true` if coverage has been #enabled, `false` otherwise.
21 22 23 |
# File 'lib/scnr/introspector/coverage.rb', line 21 def enabled? !!@enabled end |
Instance Method Details
#==(other) ⇒ Object
95 96 97 |
# File 'lib/scnr/introspector/coverage.rb', line 95 def ==( other ) hash == other.hash end |
#hash ⇒ Object
91 92 93 |
# File 'lib/scnr/introspector/coverage.rb', line 91 def hash [resources, scope].hash end |
#import_native(coverage) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/scnr/introspector/coverage.rb', line 64 def import_native( coverage ) coverage.each do |path, lines| next if @scope.out?( path ) @resources[path] ||= Resource.new( path ) lines.each.with_index do |hits, line_number| @resources[path][line_number].hit( hits ) end end self end |
#percentage ⇒ Float
Returns Percentage of coverage for all application resources which are within scope.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/scnr/introspector/coverage.rb', line 80 def percentage return 100.0 if resources.empty? total_coverages = 0 resources.each do |_, resource| total_coverages += resource.hit_percentage end total_coverages / resources.size end |
#retrieve_results ⇒ Object
60 61 62 |
# File 'lib/scnr/introspector/coverage.rb', line 60 def retrieve_results import_native( ::Coverage.result ) end |