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.
-
#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.
84 85 86 87 88 89 90 91 92 |
# File 'lib/composable_operations/operation.rb', line 84 def initialize(*args) super(args.last.kind_of?(Hash) ? args.pop : {}) @input = case args.length when 0 then nil when 1 then args.first else args end end |
Instance Attribute Details
#backtrace ⇒ Object
Returns the value of attribute backtrace.
82 83 84 |
# File 'lib/composable_operations/operation.rb', line 82 def backtrace @backtrace end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
79 80 81 |
# File 'lib/composable_operations/operation.rb', line 79 def input @input end |
#message ⇒ Object
Returns the value of attribute message.
81 82 83 |
# File 'lib/composable_operations/operation.rb', line 81 def @message end |
#result ⇒ Object
Returns the value of attribute result.
80 81 82 |
# File 'lib/composable_operations/operation.rb', line 80 def result @result end |
Class Method Details
.exception ⇒ Object
39 40 41 |
# File 'lib/composable_operations/operation.rb', line 39 def exception @exception or defined?(super) ? super : OperationError end |
.finalizers ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/composable_operations/operation.rb', line 28 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
8 9 10 11 12 13 14 15 |
# File 'lib/composable_operations/operation.rb', line 8 def perform(*args) operation = new(*args) operation.perform raise exception, operation., operation.backtrace if operation.failed? operation.result end |
.preparators ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/composable_operations/operation.rb', line 17 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
94 95 96 |
# File 'lib/composable_operations/operation.rb', line 94 def failed? state == :failed end |
#halted? ⇒ Boolean
98 99 100 |
# File 'lib/composable_operations/operation.rb', line 98 def halted? state == :halted end |
#message? ⇒ Boolean
106 107 108 |
# File 'lib/composable_operations/operation.rb', line 106 def .present? end |
#name ⇒ Object
110 111 112 |
# File 'lib/composable_operations/operation.rb', line 110 def name self.class.name end |
#perform ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/composable_operations/operation.rb', line 114 def perform self.result = catch(:halt) do prepare result = execute self.state = :succeeded result end finalize self.result end |
#succeeded? ⇒ Boolean
102 103 104 |
# File 'lib/composable_operations/operation.rb', line 102 def succeeded? state == :succeeded end |