Sha256: 341d838a67342540db57b505cab28504df2739f45e7ef10c6dbc686f3d134f9d

Contents?: true

Size: 1.62 KB

Versions: 97

Compression:

Stored size: 1.62 KB

Contents

class ForestLiana::Router
  def call(env)
    params = env['action_dispatch.request.path_parameters']
    collection_name = params[:collection]
    resource = ForestLiana::SchemaUtils.find_model_from_collection_name(collection_name, true)

    if resource.nil?
      FOREST_LOGGER.error "Routing error: Resource not found for collection #{collection_name}."
      FOREST_LOGGER.error "If this is a Smart Collection, please ensure your Smart Collection routes are defined before the mounted ForestLiana::Engine?"
      ForestLiana::BaseController.action(:route_not_found).call(env)
    else
      begin
        component_prefix = ForestLiana.component_prefix(resource)
        controller_name = "#{component_prefix}Controller"

        controller = "ForestLiana::UserSpace::#{controller_name}".constantize
        action = nil

        case env['REQUEST_METHOD']
        when 'GET'
          if params[:id]
            action = 'show'
          elsif env['PATH_INFO'] == "/#{collection_name}/count"
            action = 'count'
          else
            action = 'index'
          end
        when 'PUT'
          action = 'update'
        when 'POST'
          action = 'create'
        when 'DELETE'
          if params[:id]
            action = 'destroy'
          else
            action = 'destroy_bulk'
          end
        end

        controller.action(action.to_sym).call(env)
      rescue NoMethodError => exception
        FOREST_REPORTER.report exception
        FOREST_LOGGER.error "Routing error: #{exception}\n#{exception.backtrace.join("\n\t")}"
        ForestLiana::BaseController.action(:route_not_found).call(env)
      end
    end
  end
end

Version data entries

97 entries across 97 versions & 1 rubygems

Version Path
forest_liana-9.5.3 app/controllers/forest_liana/router.rb
forest_liana-9.5.2 app/controllers/forest_liana/router.rb
forest_liana-9.5.1 app/controllers/forest_liana/router.rb
forest_liana-9.5.0 app/controllers/forest_liana/router.rb
forest_liana-9.4.3 app/controllers/forest_liana/router.rb
forest_liana-9.4.2 app/controllers/forest_liana/router.rb
forest_liana-9.4.1 app/controllers/forest_liana/router.rb
forest_liana-9.4.0 app/controllers/forest_liana/router.rb
forest_liana-8.3.3 app/controllers/forest_liana/router.rb
forest_liana-9.3.16 app/controllers/forest_liana/router.rb
forest_liana-9.3.15 app/controllers/forest_liana/router.rb
forest_liana-9.3.14 app/controllers/forest_liana/router.rb
forest_liana-9.3.13 app/controllers/forest_liana/router.rb
forest_liana-9.3.12 app/controllers/forest_liana/router.rb
forest_liana-9.3.11 app/controllers/forest_liana/router.rb
forest_liana-9.3.10 app/controllers/forest_liana/router.rb
forest_liana-9.3.9 app/controllers/forest_liana/router.rb
forest_liana-9.3.8 app/controllers/forest_liana/router.rb
forest_liana-9.3.7 app/controllers/forest_liana/router.rb
forest_liana-9.3.6 app/controllers/forest_liana/router.rb