Module: RouteGuard::RouteTracker
- Defined in:
- lib/route_guard/route_tracker.rb
Class Attribute Summary collapse
-
.enabled ⇒ Object
Returns the value of attribute enabled.
Class Method Summary collapse
- .enable_tracking! ⇒ Object
- .find_routes_caller(locations) ⇒ Object
- .reset! ⇒ Object
- .resource_calls ⇒ Object
- .route_traces ⇒ Object
- .track_resource(type, args, scope, trace_info) ⇒ Object
- .track_route(route_object_id, trace_info) ⇒ Object
Class Attribute Details
.enabled ⇒ Object
Returns the value of attribute enabled.
6 7 8 |
# File 'lib/route_guard/route_tracker.rb', line 6 def enabled @enabled end |
Class Method Details
.enable_tracking! ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/route_guard/route_tracker.rb', line 36 def enable_tracking! return if @prepended if defined?(ActionDispatch::Routing::RouteSet) ActionDispatch::Routing::RouteSet.prepend(RouteGuard::RouteSetExtension) end if defined?(ActionDispatch::Routing::Mapper) ActionDispatch::Routing::Mapper.prepend(RouteGuard::MapperExtension) end if defined?(ActionDispatch::Routing::RouteSet::NamedRouteCollection) ActionDispatch::Routing::RouteSet::NamedRouteCollection.prepend(RouteGuard::NamedRouteCollectionExtension) end @prepended = true end |
.find_routes_caller(locations) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/route_guard/route_tracker.rb', line 54 def find_routes_caller(locations) return nil unless locations loc = locations.find do |l| path = l.path path.include?("config/routes") || path.include?("/routes.rb") || (defined?(RSpec) && path.include?("_spec.rb")) end if loc { file: loc.path, line: loc.lineno } end end |
.reset! ⇒ Object
16 17 18 19 |
# File 'lib/route_guard/route_tracker.rb', line 16 def reset! @route_traces = {} @resource_calls = [] end |
.resource_calls ⇒ Object
12 13 14 |
# File 'lib/route_guard/route_tracker.rb', line 12 def resource_calls @resource_calls ||= [] end |
.route_traces ⇒ Object
8 9 10 |
# File 'lib/route_guard/route_tracker.rb', line 8 def route_traces @route_traces ||= {} end |
.track_resource(type, args, scope, trace_info) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/route_guard/route_tracker.rb', line 26 def track_resource(type, args, scope, trace_info) return unless @enabled resource_calls << { type: type, args: args, scope: scope, trace: trace_info } end |
.track_route(route_object_id, trace_info) ⇒ Object
21 22 23 24 |
# File 'lib/route_guard/route_tracker.rb', line 21 def track_route(route_object_id, trace_info) return unless @enabled route_traces[route_object_id] = trace_info end |