Sha256: 6e338a64d00107ef7b3cd8fc0580abdc9987b8510b3e493e319dff2b13b86027

Contents?: true

Size: 1.72 KB

Versions: 5

Compression:

Stored size: 1.72 KB

Contents

# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/components/logger'
require 'contrast/extension/module'
require 'contrast/framework/rack/support'
require 'contrast/framework/rails/support'
require 'contrast/framework/grape/support'
require 'contrast/framework/sinatra/support'
require 'contrast/utils/class_util'

module Contrast
  module Framework
    # Allows access to framework specific information
    module ManagerExtend
      private

      def enable_framework_support? klass
        Contrast::Utils::ClassUtil.truly_defined?(klass)
      end

      # @return [Array<Contrast::Agent::Reporting::DiscoveredRoute>]
      def routes_for_all_frameworks
        data_for_all_frameworks(:collect_routes)
      end

      # This returns an array of all data from each framework in a flat, no-nil values array
      #
      # @param method_name [Symbol] the method to call on each FrameworkSupport class
      # @return [Array]
      def data_for_all_frameworks method_name
        @_frameworks&.flat_map { |framework| framework.send(method_name) }&.
            compact
      end

      # This returns a single object from the first framework to successfully respond
      #
      # @param method_name [Symbol] the method to call on each FrameworkSupport class
      # @return [Object] - Determined by method to be invoked
      def first_framework_result method_name, default_value
        result = nil
        return default_value if @_frameworks.empty?

        @_frameworks.each do |framework|
          result = framework.send(method_name)
          break if result
        end
        result || default_value
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
contrast-agent-7.6.1 lib/contrast/framework/manager_extend.rb
contrast-agent-7.6.0 lib/contrast/framework/manager_extend.rb
contrast-agent-7.5.0 lib/contrast/framework/manager_extend.rb
contrast-agent-7.4.1 lib/contrast/framework/manager_extend.rb
contrast-agent-7.4.0 lib/contrast/framework/manager_extend.rb