Class: ComposableOperations::ComposedOperation

Inherits:
Operation
  • Object
show all
Defined in:
lib/composable_operations/composed_operation.rb

Defined Under Namespace

Classes: OperationFactory

Instance Attribute Summary

Attributes inherited from Operation

#backtrace, #exception, #input, #message, #result

Class Method Summary collapse

Methods inherited from Operation

arguments, arity, exception, #failed?, finalizers, #halted?, #initialize, #message?, #name, perform, #perform, preparators, #succeeded?

Constructor Details

This class inherits a constructor from ComposableOperations::Operation

Class Method Details

.compose(*operations, &block) ⇒ Object

Raises:

  • (ArgumentError)


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/composable_operations/composed_operation.rb', line 35

def compose(*operations, &block)
  raise ArgumentError, "Expects either an array of operations or a block with configuration instructions" unless !!block ^ !operations.empty?

  if block
    Class.new(self, &block)
  else
    Class.new(self) do
      operations.each do |operation|
        use operation
      end
    end
  end
end

.operationsObject



22
23
24
# File 'lib/composable_operations/composed_operation.rb', line 22

def operations
  [] + Array((super if defined? super)) + Array(@operations)
end

.use(operation, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/composable_operations/composed_operation.rb', line 26

def use(operation, options = {})
  if operations.empty?
    arguments = operation.arguments
    processes(*arguments) unless arguments.empty?
  end

  (@operations ||= []) << OperationFactory.new(operation, options)
end