Sha256: 5d1a648729ba08908554d83a8b0f0a99a426c92a3de9e3c18909e2a93356ccff
Contents?: true
Size: 1.96 KB
Versions: 9
Compression:
Stored size: 1.96 KB
Contents
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/utils/string_utils' module Contrast module Api module Decorators # Used to decorate the {Contrast::Api::Dtm::RouteCoverage} protobuf model # to handle conversion between framework route classes and the dtm. module RouteCoverage def self.included klass klass.extend(ClassMethods) end # Class methods for RouteCoverage module ClassMethods 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 # Convert ActionDispatch::Journey::Route to Contrast::Api::Dtm::RouteCoverage # @param journey_obj [ActionDispatch::Journey::Route] a rails route # @return [Contrast::Api::Dtm::RouteCoverage] def from_action_dispatch_journey journey_obj msg = new msg.route = "#{ journey_obj.defaults[:controller] }##{ journey_obj.defaults[:action] }" verb = source_or_string(journey_obj.verb) msg.verb = Contrast::Utils::StringUtils.force_utf8(verb) url = source_or_string(journey_obj.path.spec) msg.url = Contrast::Utils::StringUtils.force_utf8(url) msg end def from_sinatra_route clazz, method, pattern safe_pattern = source_or_string(pattern) msg = new msg.route = "#{ clazz }##{ method } #{ safe_pattern }" msg.verb = Contrast::Utils::StringUtils.force_utf8(method) msg.url = Contrast::Utils::StringUtils.force_utf8(safe_pattern) msg end end end end end end Contrast::Api::Dtm::RouteCoverage.include(Contrast::Api::Decorators::RouteCoverage)
Version data entries
9 entries across 9 versions & 1 rubygems