Sha256: f541280a2dc204b3a147637725784ed9216149471c4aa47cb3e6047cfb7d3164

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require 'aldous/controller/preconditions_execution_service'
require 'aldous/controller/action/result_execution_service'
require 'aldous/logging_wrapper'

module Aldous
  module Controller
    class ActionExecutionService
      class << self
        def perform(controller, controller_action_class)
          self.new(controller, controller_action_class).perform
        end
      end

      attr_reader :controller, :controller_action_class

      def initialize(controller, controller_action_class)
        @controller = controller
        @controller_action_class = controller_action_class
      end

      def perform
        action = controller_action_class.build(controller)

        precondition, precondition_result = PreconditionsExecutionService.new(action, controller).perform

        # a precondition executed a render or a redirect
        return if controller.performed?

        action_result = nil
        if precondition_result
          action = precondition
          action_result = precondition_result
        else
          action_result = action.perform
        end

        # the action executed render or a redirect
        return if controller.performed?

        Action::ResultExecutionService.perform(controller, action_result, action.default_view_data)
      rescue => e
        LoggingWrapper.log(e)
        controller.head :internal_server_error
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aldous-1.0.1 lib/aldous/controller/action_execution_service.rb