Module: LightService::Action::Macros

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

Instance Method Summary collapse

Instance Method Details

#executedObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/light-service/action.rb', line 33

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
        yield(action_context)
      end
    end
  end
end

#expected_keysObject



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

def expected_keys
  @_expected_keys ||= []
end

#expects(*args) ⇒ Object



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

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

#promised_keysObject



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

def promised_keys
  @_promised_keys ||= []
end

#promises(*args) ⇒ Object



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

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

#rolled_backObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/light-service/action.rb', line 51

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