Sha256: d94d7cfdc03031201ce096f0ac959e24daa0e8669b2864233f018680287c911e

Contents?: true

Size: 1.09 KB

Versions: 16

Compression:

Stored size: 1.09 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)

    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'
        action = 'destroy'
      end

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
forest_liana-2.14.5 app/controllers/forest_liana/router.rb
forest_liana-2.14.4 app/controllers/forest_liana/router.rb
forest_liana-2.14.3 app/controllers/forest_liana/router.rb
forest_liana-2.14.2 app/controllers/forest_liana/router.rb
forest_liana-2.14.1 app/controllers/forest_liana/router.rb
forest_liana-2.14.0 app/controllers/forest_liana/router.rb
forest_liana-2.13.7 app/controllers/forest_liana/router.rb
forest_liana-2.13.6 app/controllers/forest_liana/router.rb
forest_liana-2.13.5 app/controllers/forest_liana/router.rb
forest_liana-2.13.4 app/controllers/forest_liana/router.rb
forest_liana-2.13.3 app/controllers/forest_liana/router.rb
forest_liana-2.13.2 app/controllers/forest_liana/router.rb
forest_liana-2.13.1 app/controllers/forest_liana/router.rb
forest_liana-2.13.0 app/controllers/forest_liana/router.rb
forest_liana-2.12.0 app/controllers/forest_liana/router.rb
forest_liana-2.11.13 app/controllers/forest_liana/router.rb