Class: Rack::AI::Features::Routing

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/ai/features/routing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/rack/ai/features/routing.rb', line 7

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/rack/ai/features/routing.rb', line 7

def name
  @name
end

#providerObject (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

Returns:

  • (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

Returns:

  • (Boolean)


19
20
21
# File 'lib/rack/ai/features/routing.rb', line 19

def process_response?
  false
end