Class: Rack::AI::Features::Routing
- Inherits:
-
Object
- Object
- Rack::AI::Features::Routing
- Defined in:
- lib/rack/ai/features/routing.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize(provider, config) ⇒ Routing
constructor
A new instance of Routing.
- #process_request(env) ⇒ Object
- #process_response? ⇒ Boolean
Constructor Details
#initialize(provider, config) ⇒ Routing
Returns a new instance of Routing.
9 10 11 12 13 |
# File 'lib/rack/ai/features/routing.rb', line 9 def initialize(provider, config) @name = :routing @provider = provider @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/rack/ai/features/routing.rb', line 7 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/rack/ai/features/routing.rb', line 7 def name @name end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
7 8 9 |
# File 'lib/rack/ai/features/routing.rb', line 7 def provider @provider end |
Instance Method Details
#enabled? ⇒ Boolean
15 16 17 |
# File 'lib/rack/ai/features/routing.rb', line 15 def enabled? @config.feature_enabled?(:routing) && @config.config.routing.smart_routing_enabled end |
#process_request(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rack/ai/features/routing.rb', line 23 def process_request(env) return { processed: false, reason: "disabled" } unless enabled? # Get classification and security results from other features ai_results = env["rack.ai"][:results] || {} classification = ai_results[:classification] security = ai_results[:security] routing_decision = make_routing_decision(classification, security, env) if routing_decision[:should_route] # Modify the request path for routing original_path = env["PATH_INFO"] new_path = routing_decision[:target_path] env["PATH_INFO"] = new_path env["rack.ai.original_path"] = original_path end { routing_decision: routing_decision, original_path: env["rack.ai.original_path"], new_path: env["PATH_INFO"], feature: @name, timestamp: Time.now.iso8601 } end |
#process_response? ⇒ Boolean
19 20 21 |
# File 'lib/rack/ai/features/routing.rb', line 19 def process_response? false end |