Class: Wallaby::ResourcesRouter

Inherits:
Object
  • Object
show all
Defined in:
lib/routes/wallaby/resources_router.rb

Overview

This is the core of Wallaby as it dynamically dispatches request to appropriate controller and action.

Assume that:

  • Wallaby is mounted at /admin
  • current request path is /admin/order::items, then the resources name is order::items

ResourcesRouter will try to find out which controller to dispatch to by:

  • check if the controller name Admin::Order::ItemsController exists (converted from the mount path and resources name)

  • check if the :resources_controller defaults is set when mounting Wallaby, for example:

    wallaby_mount at: '/admin', defaults: { resources_controller: CoreController }
    
  • fall back to default resources controller from Wallaby.configuration.resources_controller

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ void

This method returns an undefined value.

It dispatches the request to corresponding controller and action.

Parameters:



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/routes/wallaby/resources_router.rb', line 28

def call(env)
  options = get_options_from(env)
  validate_model_by(options[:resources])
  controller_class = find_controller_class_by(options)
  controller_class.action(options[:action]).call(env)
rescue ::AbstractController::ActionNotFound, ModelNotFound => e
  Wallaby::Logger.warn(e, sourcing: 1)
  default_controller(options).action(:not_found).call(env)
rescue UnprocessableEntity => e
  set_flash_error_for(e, env)
  default_controller(options).action(:unprocessable_entity).call(env)
end