Class: Aldous::Controller::PreconditionsExecutionService

Inherits:
Object
  • Object
show all
Defined in:
lib/aldous/controller/preconditions_execution_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action_wrapper, controller) ⇒ PreconditionsExecutionService

Returns a new instance of PreconditionsExecutionService.



9
10
11
12
# File 'lib/aldous/controller/preconditions_execution_service.rb', line 9

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

Instance Attribute Details

#action_wrapperObject (readonly)

Returns the value of attribute action_wrapper.



7
8
9
# File 'lib/aldous/controller/preconditions_execution_service.rb', line 7

def action_wrapper
  @action_wrapper
end

#controllerObject (readonly)

Returns the value of attribute controller.



7
8
9
# File 'lib/aldous/controller/preconditions_execution_service.rb', line 7

def controller
  @controller
end

Instance Method Details

#performObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/aldous/controller/preconditions_execution_service.rb', line 14

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