class Wallaby::EngineUrlFor

{Wallaby::ApplicationHelper#url_for} helper for Wallaby engine

Constants

ACTION_TO_PATH_MAP

A constant to map actions to their route paths defined in Wallaby routes.

Public Class Methods

handle(engine_name:, parameters:) click to toggle source

Generate URL that Wallaby engine supports (e.g. home/resourceful/errors) @see github.com/reinteractive/wallaby/blob/master/config/routes.rb config/routes.rb @param engine_name [string] @param parameters [ActionController::Parameters, Hash] @return [String] path string for wallaby engine @return [nil] nil if given engine name cannot be found

# File lib/services/wallaby/engine_url_for.rb, line 25
def handle(engine_name:, parameters:)
  route = Rails.application.routes.named_routes[engine_name]
  return unless route

  params = { script_name: route.path.spec.to_s }.merge(parameters).symbolize_keys

  ModuleUtils.try_to(
    Engine.routes.url_helpers, action_path_from(params), params
  )
end

Protected Class Methods

action_path_from(params) click to toggle source

Find out the named path from given params @return [Symbol] named path

# File lib/services/wallaby/engine_url_for.rb, line 40
def action_path_from(params)
  action = params[:action] || params.fetch(:_recall, {})[:action]
  ACTION_TO_PATH_MAP[action]
end