Sha256: 913c078775e4d7334e5051624b49b906b73bf334b74f55464b34ebf57e3dd5c1

Contents?: true

Size: 793 Bytes

Versions: 6

Compression:

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

    class_name = ForestLiana.name_for(resource).classify
    module_name = class_name.deconstantize

    name = module_name if module_name
    name += class_name.demodulize

    ctrl_class = "ForestLiana::UserSpace::#{name}Controller".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

    ctrl_class.action(action.to_sym).call(env)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
forest_liana-1.6.13 app/controllers/forest_liana/router.rb
forest_liana-1.6.12 app/controllers/forest_liana/router.rb
forest_liana-1.6.11 app/controllers/forest_liana/router.rb
forest_liana-1.6.10 app/controllers/forest_liana/router.rb
forest_liana-1.6.7 app/controllers/forest_liana/router.rb
forest_liana-1.6.6 app/controllers/forest_liana/router.rb