Class: Coatepec::Introspection::Routes

Inherits:
Object
  • Object
show all
Defined in:
lib/coatepec/introspection/routes.rb

Overview

Returns a bounded, filterable list of the target Rails app's routes, for the rails_routes MCP tool. Reads Rails.application.routes.routes only -- no console, no request dispatch.

Constant Summary collapse

MAX_LIMIT =
200
DEFAULT_LIMIT =
50

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query: nil, limit: DEFAULT_LIMIT, offset: 0) ⇒ Routes

Returns a new instance of Routes.



12
13
14
15
16
# File 'lib/coatepec/introspection/routes.rb', line 12

def initialize(query: nil, limit: DEFAULT_LIMIT, offset: 0)
  @query = query
  @limit = [limit || DEFAULT_LIMIT, MAX_LIMIT].min
  @offset = offset || 0
end

Class Method Details

.rails_routesObject

Isolated as a class method purely so unit tests can stub it without booting Rails -- Rails.application.routes.routes is otherwise only reachable with a real, booted application. rubocop:disable Lint/IneffectiveAccessModifier



55
56
57
# File 'lib/coatepec/introspection/routes.rb', line 55

def self.rails_routes
  Rails.application.routes.routes
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
# File 'lib/coatepec/introspection/routes.rb', line 18

def call
  matched = filtered_items
  {
    items: matched[@offset, @limit] || [],
    matched: matched.size,
    limit: @limit,
    offset: @offset
  }
end