Sha256: 936a122fe0558da0e70982007392d57facfea0a1bf99f02cc18f9239d06f88cb

Contents?: true

Size: 1.64 KB

Versions: 74

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

module Decidim
  #
  # 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 EngineRouter
    include Rails.application.routes.mounted_helpers

    # 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
    def self.main_proxy(target)
      new(target.mounted_engine, target.mounted_params)
    end

    # 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
    def self.admin_proxy(target)
      new(target.mounted_admin_engine, target.mounted_params)
    end

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

    def default_url_options
      @default_url_options.reverse_merge(ActionMailer::Base.default_url_options)
    end

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

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

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

    private

    def route_helper?(method_name)
      method_name.to_s.match?(/_(url|path)$/)
    end
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
decidim-core-0.26.10 lib/decidim/engine_router.rb
decidim-core-0.26.9 lib/decidim/engine_router.rb
decidim-core-0.26.8 lib/decidim/engine_router.rb
decidim-core-0.26.7 lib/decidim/engine_router.rb
decidim-core-0.26.5 lib/decidim/engine_router.rb
decidim-core-0.26.4 lib/decidim/engine_router.rb
decidim-core-0.26.3 lib/decidim/engine_router.rb
decidim-core-0.26.2 lib/decidim/engine_router.rb
decidim-core-0.26.1 lib/decidim/engine_router.rb
decidim-core-0.26.0 lib/decidim/engine_router.rb
decidim-core-0.26.0.rc2 lib/decidim/engine_router.rb
decidim-core-0.26.0.rc1 lib/decidim/engine_router.rb
decidim-core-0.25.2 lib/decidim/engine_router.rb
decidim-core-0.25.1 lib/decidim/engine_router.rb
decidim-core-0.25.0 lib/decidim/engine_router.rb
decidim-core-0.25.0.rc4 lib/decidim/engine_router.rb
decidim-core-0.25.0.rc3 lib/decidim/engine_router.rb
decidim-core-0.25.0.rc2 lib/decidim/engine_router.rb
decidim-core-0.25.0.rc1 lib/decidim/engine_router.rb
decidim-core-0.24.3 lib/decidim/engine_router.rb