Class: LcpRuby::Routing::PresenterRoutes

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/routing/presenter_routes.rb

Constant Summary collapse

CRUD_ROUTES =

Standard CRUD action-to-route mapping

{
  "index"   => { method: :get,    path: "/" },
  "new"     => { method: :get,    path: "/new" },
  "create"  => { method: :post,   path: "/" },
  "show"    => { method: :get,    path: "/:id" },
  "edit"    => { method: :get,    path: "/:id/edit" },
  "update"  => { method: :patch,  path: "/:id" },
  "destroy" => { method: :delete, path: "/:id" }
}.freeze
READ_ONLY_ACTIONS =
%w[index show].freeze
ROUTE_ORDER =

Ordered for correct route matching: /new before /:id

%w[index new create show edit update destroy].freeze

Class Method Summary collapse

Class Method Details

.draw_custom_controller_routes(router) ⇒ Object

Draw explicit slug-scoped routes for presenters with controller: or action_controllers:. Called BEFORE the catch-all scope “:lcp_slug” block so explicit routes take precedence.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lcp_ruby/routing/presenter_routes.rb', line 23

def draw_custom_controller_routes(router)
  return unless LcpRuby.loader&.presenter_definitions

  LcpRuby.loader.presenter_definitions.each_value do |presenter|
    next unless presenter.routable? && presenter.custom_routing?

    if presenter.custom_controller?
      draw_full_custom_routes(router, presenter)
    elsif presenter.action_controllers?
      draw_action_controller_routes(router, presenter)
    end
  end
end