Class: Contrast::Framework::Rails::Support
Overview
Used when Rails is present to define framework specific behavior
Constant Summary
collapse
- RAILS_MODULE_NAME_VERSION =
Gem::Version.new('6.0.0')
- AC_INSTANCE =
'action_controller.instance'
Class Method Summary
collapse
after_load_patches, application_name, before_load_patches!, collect_routes, current_route_coverage, detection_class, retrieve_request, server_type, streaming?, version
after_load_patches, before_load_patches!
cef_logger, logger
Class Method Details
.application_name ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/contrast/framework/rails/support.rb', line 30
def application_name
app_class = ::Rails.application.cs__class
return app_class.parent_module_name if Gem::Version.new(::Rails.version) >= RAILS_MODULE_NAME_VERSION
app_class.parent_name
end
|
.application_root ⇒ Object
39
40
41
|
# File 'lib/contrast/framework/rails/support.rb', line 39
def application_root
::Rails.root
end
|
48
49
50
|
# File 'lib/contrast/framework/rails/support.rb', line 48
def collect_routes
find_all_routes(::Rails.application, [])
end
|
Find the current route, based on the provided Request wrapper
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/contrast/framework/rails/support.rb', line 56
def current_route_coverage request
return unless ::Rails.cs__respond_to?(:application)
match, _params, route, path = get_full_route(request.rack_request)
unless route
logger.debug("Unable to determine the current route of this request: #{ request.rack_request }")
return
end
original_url = request.rack_request.path_info
mounted_app = route&.app&.app
if mounted_app && Contrast::Framework::Sinatra::Support.sinatra_controller?(mounted_app)
return mounted_new_sinatra_route(request, match, path, route, original_url)
end
if mounted_app && Contrast::Framework::Grape::Support.grape_controller?(mounted_app)
return mounted_new_grape_route(request, match, path, route, original_url)
end
new_route_coverage = Contrast::Agent::Reporting::RouteCoverage.new
new_route_coverage&.attach_rails_data(route, original_url)
new_route_coverage
rescue StandardError => e
logger.error('Unable to determine the current route of this request due to exception: ', e)
nil
end
|
.detection_class ⇒ Object
22
23
24
|
# File 'lib/contrast/framework/rails/support.rb', line 22
def detection_class
'Rails'
end
|
.retrieve_request(env) ⇒ ::ActionDispatch::Request
Copy a request for modification.
88
89
90
91
|
# File 'lib/contrast/framework/rails/support.rb', line 88
def retrieve_request env
rails_env = ::Rails.application.env_config.merge(env)
::ActionDispatch::Request.new(rails_env || env)
end
|
.server_type ⇒ Object
43
44
45
|
# File 'lib/contrast/framework/rails/support.rb', line 43
def server_type
'rails'
end
|
.streaming?(env) ⇒ Boolean
94
95
96
97
98
|
# File 'lib/contrast/framework/rails/support.rb', line 94
def streaming? env
return false unless defined?(::ActionController::Live)
env[AC_INSTANCE].cs__class.included_modules.include?(::ActionController::Live)
end
|
26
27
28
|
# File 'lib/contrast/framework/rails/support.rb', line 26
def version
::Rails.version
end
|