Class: Contrast::Framework::Manager
- Includes:
- Components::Interface
- Defined in:
- lib/contrast/framework/manager.rb
Overview
Allows access to framework specific information
Constant Summary collapse
- SUPPORTED_FRAMEWORKS =
Order here does matter as the first framework listed will be the first one we pull information from Rack will be a special case that may involve updating some logic to handle only applying Rack if Rails/Sinatra do not exist
[ Contrast::Framework::Rails::Support, Contrast::Framework::Sinatra::Support, Contrast::Framework::Rack::Support ].cs__freeze
Instance Method Summary collapse
- #app_name ⇒ Object
- #app_root ⇒ Object
-
#before_load_patches! ⇒ Object
Patches that have to be applied as early as possible to catch calls that happen prior to the first Request, typically those around configuration.
-
#find_after_load_patches ⇒ Set<Contrast::Agent::Patching::Policy::AfterLoadPatch>
Return all the After Load Patches for all the Frameworks we know, even if that Framework hasn’t been detected.
- #find_route_discovery_data ⇒ Object
- #get_route_dtm(request) ⇒ Object
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
- #platform_version ⇒ Object
-
#retrieve_request(env) ⇒ Object
If we have 0 or n > 1 frameworks, we need to use the default rack request.
- #server_type ⇒ Object
-
#streaming?(env) ⇒ Boolean
True if at least one framework is streaming the response; false if none are streaming.
Methods included from Components::Interface
Constructor Details
#initialize ⇒ Manager
Returns a new instance of Manager.
27 28 29 30 31 32 33 34 35 |
# File 'lib/contrast/framework/manager.rb', line 27 def initialize @_frameworks = SUPPORTED_FRAMEWORKS.map do |framework_klass| next unless enable_framework_support?(framework_klass.detection_class) logger.info('Framework detected. Enabling support.', framework: framework_klass.detection_class) framework_klass end @_frameworks.compact! end |
Instance Method Details
#app_name ⇒ Object
75 76 77 |
# File 'lib/contrast/framework/manager.rb', line 75 def app_name first_framework_result :application_name, 'root' end |
#app_root ⇒ Object
79 80 81 82 |
# File 'lib/contrast/framework/manager.rb', line 79 def app_root found = first_framework_result :application_root, nil found || ::Rack::Directory.new('').root end |
#before_load_patches! ⇒ Object
Patches that have to be applied as early as possible to catch calls that happen prior to the first Request, typically those around configuration.
40 41 42 43 44 45 |
# File 'lib/contrast/framework/manager.rb', line 40 def before_load_patches! @_before_load_patches ||= begin SUPPORTED_FRAMEWORKS.each(&:before_load_patches!) true end end |
#find_after_load_patches ⇒ Set<Contrast::Agent::Patching::Policy::AfterLoadPatch>
Return all the After Load Patches for all the Frameworks we know, even if that Framework hasn’t been detected.
52 53 54 55 56 57 58 59 |
# File 'lib/contrast/framework/manager.rb', line 52 def find_after_load_patches patches = Set.new SUPPORTED_FRAMEWORKS.each do |framework| framework_patches = framework.after_load_patches patches.merge(framework_patches) if framework_patches && !framework_patches.empty? end patches end |
#find_route_discovery_data ⇒ Object
61 62 63 |
# File 'lib/contrast/framework/manager.rb', line 61 def find_route_discovery_data routes_for_all_frameworks end |
#get_route_dtm(request) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/contrast/framework/manager.rb', line 105 def get_route_dtm request result = nil @_frameworks.find do |framework_klass| # TODO: RUBY-763 Sinatra::Base#call patch adds the Route report next if framework_klass == Contrast::Framework::Sinatra::Support result = framework_klass.current_route(request) end result end |
#platform_version ⇒ Object
65 66 67 68 69 |
# File 'lib/contrast/framework/manager.rb', line 65 def platform_version framework_version = first_framework_result :version, '' Contrast::Framework::PlatformVersion.from_string(framework_version) end |
#retrieve_request(env) ⇒ Object
If we have 0 or n > 1 frameworks, we need to use the default rack request
87 88 89 90 91 |
# File 'lib/contrast/framework/manager.rb', line 87 def retrieve_request env return @_frameworks[0].retrieve_request(env) if @_frameworks.length == 1 ::Rack::Request.new(env) end |
#server_type ⇒ Object
71 72 73 |
# File 'lib/contrast/framework/manager.rb', line 71 def server_type first_framework_result :server_type, 'rack' end |
#streaming?(env) ⇒ Boolean
Returns true if at least one framework is streaming the response; false if none are streaming.
96 97 98 99 100 101 102 103 |
# File 'lib/contrast/framework/manager.rb', line 96 def streaming? env result = false @_frameworks.each do |framework| result = framework.streaming?(env) break if result end result end |