Class: RoutesCoverage::Result
- Inherits:
-
Object
- Object
- RoutesCoverage::Result
- Defined in:
- lib/routes_coverage/result.rb
Instance Attribute Summary collapse
-
#all_routes ⇒ Object
readonly
Returns the value of attribute all_routes.
-
#route_hit_counts ⇒ Object
readonly
Returns the value of attribute route_hit_counts.
Instance Method Summary collapse
- #all_routes_with_hits ⇒ Object
- #avg_hits ⇒ Object
- #coverage ⇒ Object
- #coverage_pass? ⇒ Boolean
- #excluded_routes ⇒ Object
- #excluded_routes_count ⇒ Object
- #expected_routes ⇒ Object
- #expected_routes_count ⇒ Object
- #hit_routes ⇒ Object
- #hit_routes_count ⇒ Object
-
#initialize(all_routes, hit_routes, settings) ⇒ Result
constructor
A new instance of Result.
- #pending_routes ⇒ Object
- #total_count ⇒ Object
Constructor Details
#initialize(all_routes, hit_routes, settings) ⇒ Result
Returns a new instance of Result.
84 85 86 87 88 |
# File 'lib/routes_coverage/result.rb', line 84 def initialize(all_routes, hit_routes, settings) @all_routes = all_routes @route_hit_counts = hit_routes @settings = settings end |
Instance Attribute Details
#all_routes ⇒ Object (readonly)
Returns the value of attribute all_routes.
90 91 92 |
# File 'lib/routes_coverage/result.rb', line 90 def all_routes @all_routes end |
#route_hit_counts ⇒ Object (readonly)
Returns the value of attribute route_hit_counts.
90 91 92 |
# File 'lib/routes_coverage/result.rb', line 90 def route_hit_counts @route_hit_counts end |
Instance Method Details
#all_routes_with_hits ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/routes_coverage/result.rb', line 153 def all_routes_with_hits res = if Inspector::NEW_RAILS Inspector.new(all_routes).collect_all_routes else Inspector.new.collect_all_routes(all_routes) end res.each do |val| val[:hits] = @route_hit_counts[val[:original]] || 0 end res end |
#avg_hits ⇒ Object
145 146 147 |
# File 'lib/routes_coverage/result.rb', line 145 def avg_hits (@route_hit_counts.values.sum.to_f / hit_routes_count).round(@settings.round_precision) end |
#coverage ⇒ Object
139 140 141 142 143 |
# File 'lib/routes_coverage/result.rb', line 139 def coverage return 0 unless expected_routes.any? (hit_routes_count * 100.0 / expected_routes_count).round(@settings.round_precision) end |
#coverage_pass? ⇒ Boolean
149 150 151 |
# File 'lib/routes_coverage/result.rb', line 149 def coverage_pass? !@settings.minimum_coverage || (coverage.to_f >= @settings.minimum_coverage) end |
#excluded_routes ⇒ Object
113 114 115 116 |
# File 'lib/routes_coverage/result.rb', line 113 def excluded_routes expected_routes @excluded_routes end |
#excluded_routes_count ⇒ Object
131 132 133 |
# File 'lib/routes_coverage/result.rb', line 131 def excluded_routes_count excluded_routes.size end |
#expected_routes ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/routes_coverage/result.rb', line 92 def expected_routes @expected_routes ||= begin filter_regex = Regexp.union(@settings.exclude_patterns) namespaces_regex = Regexp.union(@settings.exclude_namespaces.map { |n| %r{^/#{n}} }) routes_groups = all_routes.group_by do |r| ( ("#{r.verb.to_s[8..-3]} #{r.path.spec}".strip =~ filter_regex) || (r.path.spec.to_s =~ namespaces_regex) ).present? end @excluded_routes = routes_groups[true] || [] routes_groups[false] || [] end end |
#expected_routes_count ⇒ Object
127 128 129 |
# File 'lib/routes_coverage/result.rb', line 127 def expected_routes_count expected_routes.size end |
#hit_routes ⇒ Object
118 119 120 121 |
# File 'lib/routes_coverage/result.rb', line 118 def hit_routes # TODO: sort? @route_hit_counts.keys end |
#hit_routes_count ⇒ Object
123 124 125 |
# File 'lib/routes_coverage/result.rb', line 123 def hit_routes_count @route_hit_counts.size end |
#pending_routes ⇒ Object
109 110 111 |
# File 'lib/routes_coverage/result.rb', line 109 def pending_routes expected_routes - hit_routes end |
#total_count ⇒ Object
135 136 137 |
# File 'lib/routes_coverage/result.rb', line 135 def total_count all_routes.size end |