Sha256: e445fe07f01f21800c1b791420b97d19edfabb105fe1048c664c6a0b7ee780ba

Contents?: true

Size: 714 Bytes

Versions: 1

Compression:

Stored size: 714 Bytes

Contents

require 'action_logic/action_includes'

module ActionLogic
  module ActionUseCase

    def self.included(klass)
      klass.extend ActionLogic::ActionIncludes
      klass.extend ClassMethods
    end

    module ClassMethods
      def execute(params = {})
        around(params) do |execution_context|
          raise ActionLogic::InvalidUseCaseError.new("ActionUseCase requires at least one ActionTask") if execution_context.tasks.empty?

          execution_context.call

          execution_context.tasks.reduce(execution_context.context) do |context, task|
            execution_context.context = task.execute(context)
            execution_context.context
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
action_logic-0.2.3 lib/action_logic/action_use_case.rb