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

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)


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/composable_operations/composed_operation.rb', line 29

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



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

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

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



25
26
27
# File 'lib/composable_operations/composed_operation.rb', line 25

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