Sha256: c6e949877f82561bc2e282ee36a24b1b189465b2e7dacc432b9e7665931edd48

Contents?: true

Size: 1.27 KB

Versions: 16

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Praxis
  module BootloaderStages
    class Routing < Stage
      class Target
        attr_reader :action

        def initialize(application, controller, action)
          @application = application
          @controller = controller
          @action = action
        end

        def call(request)
          dispatcher = Dispatcher.current(application: @application)
          # Switch to the sister get action if configured that way (and mark the request as forwarded)
          action = \
            if @action.sister_get_action
              request.forwarded_from_action = @action
              @action.sister_get_action
            else
              @action
            end
          dispatcher.dispatch(@controller, action, request)
        end
      end

      def execute
        application.controllers.each do |controller|
          controller.definition.actions.each do |action_name, action|
            target = target_factory(controller, action_name)
            application.router.add_route target, action.route
          end
        end
      end

      def target_factory(controller, action_name)
        action = controller.definition.actions.fetch(action_name)

        Target.new(application, controller, action)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
praxis-2.0.0 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.40 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.39 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.38 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.37 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.36 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.35 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.34 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.33 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.32 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.31 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.30 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.29 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.28 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.27 lib/praxis/bootloader_stages/routing.rb
praxis-2.0.pre.26 lib/praxis/bootloader_stages/routing.rb