Sha256: 7ea02b501884a1ffc2806bf5d145ed0ee988eb9e0d28edb5eced29586ea231b8

Contents?: true

Size: 900 Bytes

Versions: 48

Compression:

Stored size: 900 Bytes

Contents

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

    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'
        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

48 entries across 48 versions & 1 rubygems

Version Path
forest_liana-2.10.5 app/controllers/forest_liana/router.rb
forest_liana-2.10.4 app/controllers/forest_liana/router.rb
forest_liana-2.10.3 app/controllers/forest_liana/router.rb
forest_liana-2.10.2 app/controllers/forest_liana/router.rb
forest_liana-2.10.1 app/controllers/forest_liana/router.rb
forest_liana-2.10.0 app/controllers/forest_liana/router.rb
forest_liana-2.9.2 app/controllers/forest_liana/router.rb
forest_liana-2.9.1 app/controllers/forest_liana/router.rb
forest_liana-2.9.0 app/controllers/forest_liana/router.rb
forest_liana-2.8.6 app/controllers/forest_liana/router.rb
forest_liana-2.8.5 app/controllers/forest_liana/router.rb
forest_liana-2.8.4 app/controllers/forest_liana/router.rb
forest_liana-2.8.3 app/controllers/forest_liana/router.rb
forest_liana-2.8.2 app/controllers/forest_liana/router.rb
forest_liana-2.8.1 app/controllers/forest_liana/router.rb
forest_liana-2.8.0 app/controllers/forest_liana/router.rb
forest_liana-2.7.0 app/controllers/forest_liana/router.rb
forest_liana-2.6.1 app/controllers/forest_liana/router.rb
forest_liana-2.6.0 app/controllers/forest_liana/router.rb
forest_liana-2.5.5 app/controllers/forest_liana/router.rb