Module: FunctionalLightService::Action::Macros

Defined in:
lib/functional-light-service/action.rb

Instance Method Summary collapse

Instance Method Details

#ctx(*args) ⇒ Object



33
34
35
# File 'lib/functional-light-service/action.rb', line 33

def ctx(*args)
  @ctx ||= args
end

#executedObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/functional-light-service/action.rb', line 37

def executed
  define_singleton_method :execute do |context = {}|
    action_context = create_action_context(context)
    return action_context if action_context.stop_processing?

    @ctx = action_context

    # Store the action within the context
    action_context.current_action = self

    Context::KeyVerifier.verify_keys(action_context, self) do
      action_context.define_accessor_methods_for_keys(all_keys)

      catch(:jump_when_failed) do
        call_before_action(action_context)
        yield(action_context)
        call_after_action(action_context)
      end
    end
  end
end

#expected_keysObject



25
26
27
# File 'lib/functional-light-service/action.rb', line 25

def expected_keys
  @expected_keys ||= []
end

#expects(*args) ⇒ Object



17
18
19
# File 'lib/functional-light-service/action.rb', line 17

def expects(*args)
  expected_keys.concat(args)
end

#promised_keysObject



29
30
31
# File 'lib/functional-light-service/action.rb', line 29

def promised_keys
  @promised_keys ||= []
end

#promises(*args) ⇒ Object



21
22
23
# File 'lib/functional-light-service/action.rb', line 21

def promises(*args)
  promised_keys.concat(args)
end

#rolled_backObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/functional-light-service/action.rb', line 59

def rolled_back
  msg = "`rolled_back` macro can not be invoked again"
  raise msg if respond_to?(:rollback)

  define_singleton_method :rollback do |context = {}|
    yield(context)

    context
  end
end