Class: ComposableOperations::Operation
- Inherits:
-
Object
- Object
- ComposableOperations::Operation
- Includes:
- SmartProperties
- Defined in:
- lib/composable_operations/operation.rb
Direct Known Subclasses
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
readonly
Returns the value of attribute backtrace.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
- #failed? ⇒ Boolean
- #halted? ⇒ Boolean
-
#initialize(*args) ⇒ Operation
constructor
A new instance of Operation.
- #message? ⇒ Boolean
- #name ⇒ Object
- #perform ⇒ Object
- #succeeded? ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Operation
Returns a new instance of Operation.
92 93 94 95 96 97 98 99 |
# File 'lib/composable_operations/operation.rb', line 92 def initialize(*args) named_input_parameters = args.shift(self.class.arity) = args.last.kind_of?(Hash) ? args.pop : {} unnamed_input_parameters = args @input = named_input_parameters + unnamed_input_parameters super() end |
Class Attribute Details
.arity ⇒ Object
10 11 12 |
# File 'lib/composable_operations/operation.rb', line 10 def arity @arity || 0 end |
Instance Attribute Details
#backtrace ⇒ Object
Returns the value of attribute backtrace.
89 90 91 |
# File 'lib/composable_operations/operation.rb', line 89 def backtrace @backtrace end |
#exception ⇒ Object
Returns the value of attribute exception.
90 91 92 |
# File 'lib/composable_operations/operation.rb', line 90 def exception @exception end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
86 87 88 |
# File 'lib/composable_operations/operation.rb', line 86 def input @input end |
#message ⇒ Object
Returns the value of attribute message.
88 89 90 |
# File 'lib/composable_operations/operation.rb', line 88 def @message end |
#result ⇒ Object
Returns the value of attribute result.
87 88 89 |
# File 'lib/composable_operations/operation.rb', line 87 def result @result end |
Class Method Details
.exception ⇒ Object
45 46 47 |
# File 'lib/composable_operations/operation.rb', line 45 def exception OperationError end |
.finalizers ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/composable_operations/operation.rb', line 34 def finalizers finalizers = [] klass = self while klass != Operation klass = klass.superclass finalizers += Array(klass.instance_variable_get(:@finalizers)) end finalizers += Array(@finalizers) finalizers end |
.perform(*args) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/composable_operations/operation.rb', line 14 def perform(*args) operation = new(*args) operation.perform raise operation.exception if operation.failed? operation.result end |
.preparators ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/composable_operations/operation.rb', line 23 def preparators preparators = [] klass = self while klass != Operation klass = klass.superclass preparators += Array(klass.instance_variable_get(:@preparators)) end preparators += Array(@preparators) preparators end |
Instance Method Details
#failed? ⇒ Boolean
101 102 103 |
# File 'lib/composable_operations/operation.rb', line 101 def failed? state == :failed end |
#halted? ⇒ Boolean
105 106 107 |
# File 'lib/composable_operations/operation.rb', line 105 def halted? state == :halted end |
#message? ⇒ Boolean
113 114 115 |
# File 'lib/composable_operations/operation.rb', line 113 def .present? end |
#name ⇒ Object
117 118 119 |
# File 'lib/composable_operations/operation.rb', line 117 def name self.class.name end |
#perform ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/composable_operations/operation.rb', line 121 def perform self.result = catch(:halt) do prepare result = execute self.state = :succeeded result end finalize self.result end |
#succeeded? ⇒ Boolean
109 110 111 |
# File 'lib/composable_operations/operation.rb', line 109 def succeeded? state == :succeeded end |