class Decidim::EngineRouter

This class is responsible for sending route helper methods to the correct mounted engine. To do that, it needs to know the name of the mounted helper for the engine, and the contextual parameters to identify the mount point for it, which are added to the parameters passed to the route helper.

Public Class Methods

admin_proxy(target) click to toggle source

Instantiates a router to the backend engine for an object.

@param target [#mounted_admin_engine, mounted_params] Object to be routed

@return [EngineRouter] The new engine router

# File lib/decidim/engine_router.rb, line 27
def self.admin_proxy(target)
  new(target.mounted_admin_engine, target.mounted_params)
end
main_proxy(target) click to toggle source

Instantiates a router to the frontend engine for an object.

@param target [#mounted_engine, mounted_params] Object to be routed

@return [EngineRouter] The new engine router

# File lib/decidim/engine_router.rb, line 18
def self.main_proxy(target)
  new(target.mounted_engine, target.mounted_params)
end
new(engine, default_url_options) click to toggle source
# File lib/decidim/engine_router.rb, line 31
def initialize(engine, default_url_options)
  @engine = engine
  @default_url_options = default_url_options
end

Public Instance Methods

default_url_options() click to toggle source
# File lib/decidim/engine_router.rb, line 36
def default_url_options
  @default_url_options.reverse_merge(ActionMailer::Base.default_url_options)
end
method_missing(method_name, *args) click to toggle source
Calls superclass method
# File lib/decidim/engine_router.rb, line 44
def method_missing(method_name, *args)
  return super unless route_helper?(method_name)

  send(@engine).send(method_name, *args)
end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/decidim/engine_router.rb, line 40
def respond_to_missing?(method_name, include_private = false)
  route_helper?(method_name) || super
end

Private Instance Methods

route_helper?(method_name) click to toggle source
# File lib/decidim/engine_router.rb, line 52
def route_helper?(method_name)
  method_name.to_s.match?(/_(url|path)$/)
end