module FunctionalLightService::Action::Macros

Public Instance Methods

ctx(*args) click to toggle source
# File lib/functional-light-service/action.rb, line 33
def ctx(*args)
  @ctx ||= args
end
executed() { |action_context| ... } click to toggle source
# 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_keys() click to toggle source
# File lib/functional-light-service/action.rb, line 25
def expected_keys
  @expected_keys ||= []
end
expects(*args) click to toggle source
# File lib/functional-light-service/action.rb, line 17
def expects(*args)
  expected_keys.concat(args)
end
promised_keys() click to toggle source
# File lib/functional-light-service/action.rb, line 29
def promised_keys
  @promised_keys ||= []
end
promises(*args) click to toggle source
# File lib/functional-light-service/action.rb, line 21
def promises(*args)
  promised_keys.concat(args)
end
rolled_back() { |context| ... } click to toggle source
# 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

Private Instance Methods

all_keys() click to toggle source
# File lib/functional-light-service/action.rb, line 78
def all_keys
  expected_keys + promised_keys
end
call_after_action(context) click to toggle source
# File lib/functional-light-service/action.rb, line 86
def call_after_action(context)
  invoke_callbacks(context[:_after_actions], context)
end
call_before_action(context) click to toggle source
# File lib/functional-light-service/action.rb, line 82
def call_before_action(context)
  invoke_callbacks(context[:_before_actions], context)
end
create_action_context(context) click to toggle source
# File lib/functional-light-service/action.rb, line 72
def create_action_context(context)
  return context if context.is_a? FunctionalLightService::Context

  FunctionalLightService::Context.make(context)
end
invoke_callbacks(callbacks, context) click to toggle source
# File lib/functional-light-service/action.rb, line 90
def invoke_callbacks(callbacks, context)
  return context unless callbacks

  callbacks.each do |cb|
    cb.call(context)
  end

  context
end