Class: ComposableOperations::ComposedOperation
- Inherits:
-
Operation
- Object
- Operation
- ComposableOperations::ComposedOperation
show all
- Defined in:
- lib/composable_operations/composed_operation.rb
Instance Attribute Summary
Attributes inherited from Operation
#backtrace, #input, #message, #result
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Operation
exception, #failed?, finalizers, #halted?, #initialize, #message?, #name, perform, #perform, preparators, #succeeded?
Class Method Details
.compose(*operations, &block) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/composable_operations/composed_operation.rb', line 13
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
|
.operations ⇒ Object
5
6
7
|
# File 'lib/composable_operations/composed_operation.rb', line 5
def operations
[] + Array((super if defined? super)) + Array(@operations)
end
|
.transitions ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/composable_operations/composed_operation.rb', line 27
def transitions
transitions = []
klass = self
while klass != Operation
klass = klass.superclass
transitions += Array(klass.instance_variable_get(:@transitions))
end
transitions += Array(@transitions)
transitions
end
|
.use(operation) ⇒ Object
9
10
11
|
# File 'lib/composable_operations/composed_operation.rb', line 9
def use(operation)
(@operations ||= []) << operation
end
|
Instance Method Details
#operations ⇒ Object
47
48
49
|
# File 'lib/composable_operations/composed_operation.rb', line 47
def operations
self.class.operations
end
|