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, 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, controller)
  @action = action
  @controller = controller
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



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

def action
  @action
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
28
# File 'lib/aldous/controller/preconditions_execution_service.rb', line 14

def perform
  if action.respond_to?(:preconditions) && !action.preconditions.empty?
    action.preconditions.each do |precondition_class|
      # action here is actually an action wrapper hence the
      # action.controller_action below
      precondition = precondition_class.build(action.controller_action)
      precondition_result = precondition.perform

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