Class: ComposableOperations::Operation
- Inherits:
-
Object
- Object
- ComposableOperations::Operation
- Includes:
- SmartProperties
- Defined in:
- lib/composable_operations/operation.rb
Direct Known Subclasses
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
- .arguments ⇒ Object
- .arity ⇒ Object
- .exception ⇒ Object
- .finalizers ⇒ Object
- .perform(*args) ⇒ Object
- .preparators ⇒ Object
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.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/composable_operations/operation.rb', line 89 def initialize(*args) arity = self.class.arity arguments = args.shift(arity) attributes = args.last.kind_of?(Hash) ? args.pop : {} raise ArgumentError, "wrong number of arguments #{arguments.length + args.length} for #{arity}" unless args.empty? self.class.arguments.each_with_index do |name, index| attributes[name] = arguments[index] end super(attributes) end |
Instance Attribute Details
#backtrace ⇒ Object
Returns the value of attribute backtrace.
86 87 88 |
# File 'lib/composable_operations/operation.rb', line 86 def backtrace @backtrace end |
#exception ⇒ Object
Returns the value of attribute exception.
87 88 89 |
# File 'lib/composable_operations/operation.rb', line 87 def exception @exception end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
83 84 85 |
# File 'lib/composable_operations/operation.rb', line 83 def input @input end |
#message ⇒ Object
Returns the value of attribute message.
85 86 87 |
# File 'lib/composable_operations/operation.rb', line 85 def @message end |
#result ⇒ Object
Returns the value of attribute result.
84 85 86 |
# File 'lib/composable_operations/operation.rb', line 84 def result @result end |
Class Method Details
.arguments ⇒ Object
7 8 9 |
# File 'lib/composable_operations/operation.rb', line 7 def arguments [] end |
.arity ⇒ Object
11 12 13 |
# File 'lib/composable_operations/operation.rb', line 11 def arity arguments.count end |
.exception ⇒ Object
46 47 48 |
# File 'lib/composable_operations/operation.rb', line 46 def exception OperationError end |
.finalizers ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/composable_operations/operation.rb', line 35 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
15 16 17 18 19 20 21 22 |
# File 'lib/composable_operations/operation.rb', line 15 def perform(*args) operation = new(*args) operation.perform raise operation.exception if operation.failed? operation.result end |
.preparators ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/composable_operations/operation.rb', line 24 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
107 108 109 |
# File 'lib/composable_operations/operation.rb', line 107 def failed? state == :failed end |
#halted? ⇒ Boolean
111 112 113 |
# File 'lib/composable_operations/operation.rb', line 111 def halted? state == :halted end |
#message? ⇒ Boolean
119 120 121 |
# File 'lib/composable_operations/operation.rb', line 119 def .present? end |
#name ⇒ Object
123 124 125 |
# File 'lib/composable_operations/operation.rb', line 123 def name self.class.name end |
#perform ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/composable_operations/operation.rb', line 127 def perform self.result = catch(:halt) do prepare result = execute self.state = :succeeded result end finalize self.result end |
#succeeded? ⇒ Boolean
115 116 117 |
# File 'lib/composable_operations/operation.rb', line 115 def succeeded? state == :succeeded end |