Sha256: 26439e5118d77fa02e6dbcf233f069ca8ab6fbce90dceac7463b82a43f81f7fa

Contents?: true

Size: 1 KB

Versions: 12

Compression:

Stored size: 1 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
      ForestLiana::ApplicationController.action(:route_not_found).call(env)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
forest_liana-2.11.12 app/controllers/forest_liana/router.rb
forest_liana-2.11.11 app/controllers/forest_liana/router.rb
forest_liana-2.11.10 app/controllers/forest_liana/router.rb
forest_liana-2.11.9 app/controllers/forest_liana/router.rb
forest_liana-2.11.8 app/controllers/forest_liana/router.rb
forest_liana-2.11.7 app/controllers/forest_liana/router.rb
forest_liana-2.11.6 app/controllers/forest_liana/router.rb
forest_liana-2.11.5 app/controllers/forest_liana/router.rb
forest_liana-2.11.4 app/controllers/forest_liana/router.rb
forest_liana-2.11.3 app/controllers/forest_liana/router.rb
forest_liana-2.11.2 app/controllers/forest_liana/router.rb
forest_liana-2.11.1 app/controllers/forest_liana/router.rb