Sha256: 57c50872b53a8e0b1a7d9566a23ae50627525d582b26f2407d6705b656bf565f

Contents?: true

Size: 950 Bytes

Versions: 2

Compression:

Stored size: 950 Bytes

Contents

require 'aldous/respondable/base'
require 'aldous/controller/action/precondition/wrapper'

module Aldous
  module Controller
    class PreconditionsExecutionService
      attr_reader :action_wrapper, :controller

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

      def perform
        if action_wrapper.respond_to?(:preconditions) && !action_wrapper.preconditions.empty?
          action_wrapper.preconditions.each do |precondition_class|
            action = action_wrapper.controller_action
            precondition = precondition_class.build(action, controller, action.view_builder)
            precondition_result = precondition.perform

            if precondition_result.kind_of?(::Aldous::Respondable::Base)
              return [precondition, precondition_result]
            end
          end
        end
        [nil, nil]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aldous-1.1.3 lib/aldous/controller/preconditions_execution_service.rb
aldous-1.1.2 lib/aldous/controller/preconditions_execution_service.rb