Module: FunctionalLightService::Action::Macros

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

Instance Method Summary collapse

Instance Method Details

#executedObject



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

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

    # 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



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

def expected_keys
  @expected_keys ||= []
end

#expects(*args) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/functional-light-service/action.rb', line 19

def expects(*args)
  if expect_key_having_default?(args)
    available_defaults[args.first] = args.last[:default]

    args = [args.first]
  end

  expected_keys.concat(args)
end

#promised_keysObject



37
38
39
# File 'lib/functional-light-service/action.rb', line 37

def promised_keys
  @promised_keys ||= []
end

#promises(*args) ⇒ Object



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

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

#rolled_backObject



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

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