Class: Contrast::Agent::Reporting::RouteCoverage
- Defined in:
- lib/contrast/agent/reporting/reporting_events/route_coverage.rb
Overview
This is the new Route Coverage class which will include all the needed information for the new reporting system to relay this information in the Route Observation messages. These observations are used by TeamServer to construct the route coverage information for the assess feature. They represent those methods which map to externally accessible endpoints within the application, as registered to the application framework. This also includes the literal URL and HTTP Verb used to invoke them, as they must have been called at this point to be recorded.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#attach_rack_based_data(final_controller, method, route_pattern, url = nil) ⇒ Contrast::Agent::Reporting::RouteCoverage
Parse the given controller and route from a Rack based application framework in order to create an instance of this class.
-
#attach_rails_data(journey_obj, url = nil) ⇒ Contrast::Agent::Reporting::RouteCoverage
Convert ActionDispatch::Journey::Route to Contrast::Agent::Reporting::RouteCoverage.
-
#initialize ⇒ RouteCoverage
constructor
A new instance of RouteCoverage.
- #source_or_string(obj) ⇒ Object
Constructor Details
#initialize ⇒ RouteCoverage
Returns a new instance of RouteCoverage.
26 27 28 29 30 31 |
# File 'lib/contrast/agent/reporting/reporting_events/route_coverage.rb', line 26 def initialize @route = Contrast::Utils::ObjectShare::EMPTY_STRING @verb = Contrast::Utils::ObjectShare::EMPTY_STRING @url = Contrast::Utils::ObjectShare::EMPTY_STRING @count = 0 end |
Instance Attribute Details
#count ⇒ Object (readonly)
24 25 26 |
# File 'lib/contrast/agent/reporting/reporting_events/route_coverage.rb', line 24 def count @count end |
#route ⇒ Object
18 19 20 |
# File 'lib/contrast/agent/reporting/reporting_events/route_coverage.rb', line 18 def route @route end |
#url ⇒ Object
20 21 22 |
# File 'lib/contrast/agent/reporting/reporting_events/route_coverage.rb', line 20 def url @url end |
#verb ⇒ Object
22 23 24 |
# File 'lib/contrast/agent/reporting/reporting_events/route_coverage.rb', line 22 def verb @verb end |
Instance Method Details
#attach_rack_based_data(final_controller, method, route_pattern, url = nil) ⇒ Contrast::Agent::Reporting::RouteCoverage
Parse the given controller and route from a Rack based application framework in order to create an instance of this class
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/contrast/agent/reporting/reporting_events/route_coverage.rb', line 42 def attach_rack_based_data final_controller, method, route_pattern, url = nil if Contrast::Utils::ClassUtil.truly_defined?('Grape::Router::Route') && route_pattern.cs__is_a?(Grape::Router::Route) safe_pattern = route_pattern.pattern&.path&.to_s safe_url = source_or_string(url || safe_pattern) else safe_pattern = source_or_string(route_pattern) safe_url = source_or_string(url || route_pattern) end self.route = "#{ final_controller }##{ method } #{ safe_pattern }" self.verb = Contrast::Utils::StringUtils.force_utf8(method) self.url = Contrast::Utils::StringUtils.force_utf8(safe_url) self end |
#attach_rails_data(journey_obj, url = nil) ⇒ Contrast::Agent::Reporting::RouteCoverage
Convert ActionDispatch::Journey::Route to Contrast::Agent::Reporting::RouteCoverage
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/contrast/agent/reporting/reporting_events/route_coverage.rb', line 64 def attach_rails_data journey_obj, url = nil self.route = "#{ journey_obj.defaults[:controller] }##{ journey_obj.defaults[:action] }" verb = source_or_string(journey_obj.verb) self.verb = Contrast::Utils::StringUtils.force_utf8(verb) url ||= source_or_string(journey_obj.path.spec) self.url = Contrast::Utils::StringUtils.force_utf8(url) self end |
#source_or_string(obj) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/contrast/agent/reporting/reporting_events/route_coverage.rb', line 75 def source_or_string obj if obj.cs__is_a?(Regexp) obj.source elsif obj.cs__respond_to?(:safe_string) obj.safe_string else obj.to_s end end |