Sha256: 856c3d47a2de663ef0b6d4875d41d0cb8311b87683c3894dcdc2d24f2bb25a3a

Contents?: true

Size: 1018 Bytes

Versions: 15

Compression:

Stored size: 1018 Bytes

Contents

module Jets::Controller::RackAdapter
  module Action
    extend ActiveSupport::Concern

    class_methods do
      def action(name)
        lambda do |env|
          route = find_first_route_for_action(name)
          env['PATH_INFO'] = route_path(route)
          controller = new({}, {}, name, env)
          controller.dispatch! # does not go through middleware stack
        end
      end

      # Find first route to be used for PATH_INFO.
      # This allows engine_delegate to work properly.
      def find_first_route_for_action(name)
        Jets::Router.routes.find do |r|
          route_controller_path, route_action_name = r.to.split('#')
          route_controller_path == controller_path && route_action_name == name.to_s
        end
      end

      def route_path(route)
        if route
          path = route.path
          path = "/#{path}" unless path.starts_with?('/')
        else
          path = "/#{controller_path}##{name} (action proc)"
        end
        path
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
jets-5.0.13 lib/jets/controller/rack_adapter/action.rb
jets-5.0.12 lib/jets/controller/rack_adapter/action.rb
jets-5.0.11 lib/jets/controller/rack_adapter/action.rb
jets-5.0.10 lib/jets/controller/rack_adapter/action.rb
jets-5.0.9 lib/jets/controller/rack_adapter/action.rb
jets-5.0.8 lib/jets/controller/rack_adapter/action.rb
jets-5.0.7 lib/jets/controller/rack_adapter/action.rb
jets-5.0.6 lib/jets/controller/rack_adapter/action.rb
jets-5.0.5 lib/jets/controller/rack_adapter/action.rb
jets-5.0.4 lib/jets/controller/rack_adapter/action.rb
jets-5.0.3 lib/jets/controller/rack_adapter/action.rb
jets-5.0.2 lib/jets/controller/rack_adapter/action.rb
jets-5.0.1 lib/jets/controller/rack_adapter/action.rb
jets-5.0.0 lib/jets/controller/rack_adapter/action.rb
jets-5.0.0.beta1 lib/jets/controller/rack_adapter/action.rb