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.
-
#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
A lookup table for resource route configurations.
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) ActiveSupport::Notifications.instrument("plutonium.resource_routes.draw", app: engine.to_s) do super do setup_shared_resource_concerns instance_exec(&block) materialize_resource_routes end end else super end end |
#engine ⇒ Class
Returns the current engine for the routes.
81 82 83 |
# File 'lib/plutonium/routing/route_set_extensions.rb', line 81 def engine @engine ||= determine_engine end |
#register_resource(resource, options = {}) { ... } ⇒ Hash
Registers a resource for routing.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/plutonium/routing/route_set_extensions.rb', line 56 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.
73 74 75 76 |
# File 'lib/plutonium/routing/route_set_extensions.rb', line 73 def resource_route_config_for(*routes) routes = Array(routes) resource_route_config_lookup.slice(*routes).values end |
#resource_route_config_lookup ⇒ Hash
Returns A lookup table for resource route configurations.
86 87 88 |
# File 'lib/plutonium/routing/route_set_extensions.rb', line 86 def resource_route_config_lookup @resource_route_config_lookup ||= {} end |