Class: InstantApi::Controller::Routes

Inherits:
Object
  • Object
show all
Defined in:
lib/instant_api/controller/routes.rb

Instance Method Summary collapse

Constructor Details

#initializeRoutes

Returns a new instance of Routes.



7
8
9
10
11
12
# File 'lib/instant_api/controller/routes.rb', line 7

def initialize
  Rails.application.reload_routes!
  @routes = Rails.application.routes.routes.map do |route|
    ActionDispatch::Routing::RouteWrapper.new(route)
  end.reject(&:internal?)
end

Instance Method Details

#build_controllersObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/instant_api/controller/routes.rb', line 14

def build_controllers
  controllers_by_routes = Hash.new
  @routes.each do |route|
    controller = route.defaults[:controller]
    list = controllers_by_routes[controller] || []
    controllers_by_routes[controller] = list << route
  end

  controllers = controllers_by_routes.map do |controller, routes|
    methods = routes.map { |route| route.defaults[:action] }
    [controller, methods]
  end

  controllers.each do |controller, methods|
    InstantApi::Controller::Builder.new(controller, methods).build_class
  end
end