Module: Plutonium::Routing::RouteSetExtensions
- Extended by:
- ActiveSupport::Concern
- Includes:
- Engine::Validator
- Defined in:
- lib/plutonium/routing/route_set_extensions.rb
Overview
RouteSetExtensions module provides additional functionality for route management in Plutonium applications.
This module extends the functionality of Rails’ routing system to support Plutonium-specific features, such as resource registration and custom route drawing.
Instance Method Summary collapse
-
#clear! ⇒ void
Clears all registered resources and route configurations.
-
#draw(&block) { ... } ⇒ void
Draws routes with additional Plutonium-specific setup and resource materialization.
-
#engine ⇒ Class
Returns the current engine for the routes.
-
#entity_scope_params_for_path_strategy ⇒ Hash?
Determines entity scope parameters for path-based scoping.
-
#register_resource(resource, options = {}) { ... } ⇒ Hash
Registers a resource for routing.
-
#resource_route_config_for(*routes) ⇒ Array<Hash>
Retrieves the route configuration for specified routes.
-
#resource_route_config_lookup ⇒ Hash
Keys are either plural names (e.g., “profiles”) for top-level routes or “parent_plural/child_plural” (e.g., “users/profiles”) for nested routes.
-
#singular_resource_route?(route_key) ⇒ Boolean
Checks if a resource is registered as a singular route.
Instance Method Details
#clear! ⇒ void
This method returns an undefined value.
Clears all registered resources and route configurations.
This method should be called when you want to reset all registered resources and start with a clean slate for route definition.
24 25 26 27 28 |
# File 'lib/plutonium/routing/route_set_extensions.rb', line 24 def clear! resource_route_config_lookup.clear engine.resource_register.clear super end |
#draw(&block) { ... } ⇒ void
This method returns an undefined value.
Draws routes with additional Plutonium-specific setup and resource materialization.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/plutonium/routing/route_set_extensions.rb', line 35 def draw(&block) if self.class.supported_engine?(engine) scope_params = entity_scope_params_for_path_strategy ActiveSupport::Notifications.instrument("plutonium.resource_routes.draw", app: engine.to_s) do super do setup_shared_resource_concerns draw_routes_with_entity_scope(scope_params, &block) end end else super end end |
#engine ⇒ Class
Returns the current engine for the routes.
102 103 104 |
# File 'lib/plutonium/routing/route_set_extensions.rb', line 102 def engine @engine ||= determine_engine end |
#entity_scope_params_for_path_strategy ⇒ Hash?
Determines entity scope parameters for path-based scoping.
52 53 54 55 56 57 58 59 60 |
# File 'lib/plutonium/routing/route_set_extensions.rb', line 52 def entity_scope_params_for_path_strategy return nil unless engine.scoped_entity_strategy == :path param_key = engine.scoped_entity_param_key { name: ":#{param_key}", options: {as: param_key} } end |
#register_resource(resource, options = {}) { ... } ⇒ Hash
Registers a resource for routing.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/plutonium/routing/route_set_extensions.rb', line 69 def register_resource(resource, = {}, &) self.class.validate_engine! engine engine.resource_register.register(resource) route_name = resource.model_name.plural concern_name = :"#{route_name}_routes" config = create_resource_config(resource, route_name, concern_name, , &) resource_route_config_lookup[route_name] = config config end |
#resource_route_config_for(*routes) ⇒ Array<Hash>
Retrieves the route configuration for specified routes.
86 87 88 89 |
# File 'lib/plutonium/routing/route_set_extensions.rb', line 86 def resource_route_config_for(*routes) routes = Array(routes) resource_route_config_lookup.slice(*routes).values end |
#resource_route_config_lookup ⇒ Hash
Keys are either plural names (e.g., “profiles”) for top-level routes or “parent_plural/child_plural” (e.g., “users/profiles”) for nested routes.
109 110 111 |
# File 'lib/plutonium/routing/route_set_extensions.rb', line 109 def resource_route_config_lookup @resource_route_config_lookup ||= {} end |
#singular_resource_route?(route_key) ⇒ Boolean
Checks if a resource is registered as a singular route.
95 96 97 |
# File 'lib/plutonium/routing/route_set_extensions.rb', line 95 def singular_resource_route?(route_key) resource_route_config_for(route_key)[0]&.[](:route_type) == :resource end |