Module: ActionLogic::ActionCore::ClassMethods

Defined in:
lib/action_logic/action_core.rb

Instance Method Summary collapse

Instance Method Details

#around(params, &block) ⇒ Object



19
20
21
22
23
# File 'lib/action_logic/action_core.rb', line 19

def around(params, &block)
  with_benchmark(self) do
    execute!(params, &block)
  end
end

#execute!(params, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/action_logic/action_core.rb', line 25

def execute!(params, &block)
  execution_context = self.new(params)

  return execution_context.context if execution_context.break?

  execution_context.set_validation_rules
  execution_context.validations!(:before)
  execution_context.validations!(:around)

  begin
    block.call(execution_context)
  rescue => e
    if execution_context.respond_to?(:error)
      execution_context.error(e)
    else
      raise e
    end
  end

  execution_context.validations!(:after)
  execution_context.validations!(:around)

  execution_context.context
end