Class: Decidim::EngineRouter

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/engine_router.rb

Overview

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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, default_url_options, target = nil) ⇒ EngineRouter

Returns a new instance of EngineRouter.



31
32
33
34
35
# File 'lib/decidim/engine_router.rb', line 31

def initialize(engine, default_url_options, target = nil)
  @engine = engine
  @default_url_options = default_url_options
  @target = target
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/decidim/engine_router.rb', line 45

def method_missing(method_name, *)
  return super unless route_helper?(method_name)

  filter_slug_params!(method_name)

  send(engine).send(method_name, *)
end

Class Method Details

.admin_proxy(target) ⇒ EngineRouter

Instantiates a router to the backend engine for an object.

Parameters:

  • target (#mounted_admin_engine, #mounted_params)

    Object to be routed

Returns:



27
28
29
# File 'lib/decidim/engine_router.rb', line 27

def self.admin_proxy(target)
  new(target.mounted_admin_engine, target.mounted_params, target)
end

.main_proxy(target) ⇒ EngineRouter

Instantiates a router to the frontend engine for an object.

Parameters:

  • target (#mounted_engine, #mounted_params)

    Object to be routed

Returns:



18
19
20
# File 'lib/decidim/engine_router.rb', line 18

def self.main_proxy(target)
  new(target.mounted_engine, target.mounted_params, target)
end

Instance Method Details

#default_url_optionsObject



37
38
39
# File 'lib/decidim/engine_router.rb', line 37

def default_url_options
  @default_url_options.reverse_merge(configured_default_url_options)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/decidim/engine_router.rb', line 41

def respond_to_missing?(method_name, include_private = false)
  route_helper?(method_name) || super
end