Class: Clomp::Operation
- Inherits:
-
Object
- Object
- Clomp::Operation
- Defined in:
- lib/clomp/operation.rb
Class Attribute Summary collapse
-
.configs ⇒ Object
To store and read all the tracks!.
-
.track_builders ⇒ Object
To store and read all the tracks!.
Instance Attribute Summary collapse
-
#configs ⇒ Object
readonly
Returns the value of attribute configs.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
- .[](mutable_data = {}, immutable_data = {}) ⇒ Object
- .call(mutable_data = {}, immutable_data = {}) ⇒ Object
-
.failure(track_name, track_options: {}, &block) ⇒ Object
get the track name for the failure case!.
-
.finally(track_name, track_options: {}, &block) ⇒ Object
get the track name for the final step! Only one step will be executed!.
-
.setup {|config| ... } ⇒ Configuration
(also: setup_configuration)
Operation wise configuration to control state All operation may not require fail fast All operation may not require pass fast Operation wise optional value could be different.
-
.share(track_name, from:, track_options: {}, &block) ⇒ Object
Share track from other operation.
-
.track(track_name, track_options: {}, &block) ⇒ Object
get track name and options!.
Instance Method Summary collapse
-
#exec_steps! ⇒ Object
Execute all the steps! Execute all the tracks!.
- #executed_steps ⇒ Object
-
#initialize(track_builders: [], options: {}, exec: true) ⇒ self
constructor
Constructor for operation object.
-
#steps ⇒ Object
Name of the steps defined in the operation class.
Constructor Details
#initialize(track_builders: [], options: {}, exec: true) ⇒ self
Constructor for operation object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/clomp/operation.rb', line 10 def initialize(track_builders: [], options: {}, exec: true) @options = # Setup result object! @result = Result.new( operation: self, tracks: track_builders || [], options: || {} ) @configs = self.class.setup_configuration exec_steps! if exec end |
Class Attribute Details
.configs ⇒ Object
To store and read all the tracks!
41 42 43 |
# File 'lib/clomp/operation.rb', line 41 def configs @configs end |
.track_builders ⇒ Object
To store and read all the tracks!
41 42 43 |
# File 'lib/clomp/operation.rb', line 41 def track_builders @track_builders end |
Instance Attribute Details
#configs ⇒ Object (readonly)
Returns the value of attribute configs.
3 4 5 |
# File 'lib/clomp/operation.rb', line 3 def configs @configs end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
3 4 5 |
# File 'lib/clomp/operation.rb', line 3 def result @result end |
Class Method Details
.[](mutable_data = {}, immutable_data = {}) ⇒ Object
93 94 95 |
# File 'lib/clomp/operation.rb', line 93 def [](mutable_data = {}, immutable_data = {}) self.(mutable_data, immutable_data) end |
.call(mutable_data = {}, immutable_data = {}) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/clomp/operation.rb', line 97 def call(mutable_data = {}, immutable_data = {}) new( track_builders: @track_builders, options: { mutable_data: mutable_data, immutable_data: immutable_data }, ).result end |
.failure(track_name, track_options: {}, &block) ⇒ Object
get the track name for the failure case!
80 81 82 83 84 |
# File 'lib/clomp/operation.rb', line 80 def failure(track_name, track_options: {}, &block) @track_builders ||= [] @track_builders << build_track(track_name, , :failed_track, track_for: nil, &block) end |
.finally(track_name, track_options: {}, &block) ⇒ Object
get the track name for the final step! Only one step will be executed!
87 88 89 90 91 |
# File 'lib/clomp/operation.rb', line 87 def finally(track_name, track_options: {}, &block) @track_builders ||= [] @track_builders << build_track(track_name, , :finally, track_for: nil, &block) end |
.setup {|config| ... } ⇒ Configuration Also known as: setup_configuration
Operation wise configuration to control state All operation may not require fail fast All operation may not require pass fast Operation wise optional value could be different
51 52 53 54 55 56 57 |
# File 'lib/clomp/operation.rb', line 51 def setup @configs ||= Configuration.new yield(@configs) if block_given? @configs end |
.share(track_name, from:, track_options: {}, &block) ⇒ Object
Share track from other operation
62 63 64 65 66 67 68 69 70 |
# File 'lib/clomp/operation.rb', line 62 def share(track_name, from:, track_options: {}, &block) @track_builders ||= [] _callable_class = from && from.kind_of?(String) ? Object.const_get(from) : from raise UnknownOperation, 'Please provide a valid operation to share the steps for' unless _callable_class @track_builders << build_track(track_name, , :track, track_for: _callable_class , &block) end |
.track(track_name, track_options: {}, &block) ⇒ Object
get track name and options!
73 74 75 76 77 |
# File 'lib/clomp/operation.rb', line 73 def track(track_name, track_options: {}, &block) @track_builders ||= [] @track_builders << build_track(track_name, , :track, track_for: nil, &block) end |
Instance Method Details
#exec_steps! ⇒ Object
Execute all the steps! Execute all the tracks!
25 26 27 |
# File 'lib/clomp/operation.rb', line 25 def exec_steps! Executor[result, @options, _self: self] end |
#executed_steps ⇒ Object
29 30 31 |
# File 'lib/clomp/operation.rb', line 29 def executed_steps @result['tracks'].collect {|track| track.name if track.success?}.compact end |
#steps ⇒ Object
Name of the steps defined in the operation class
34 35 36 |
# File 'lib/clomp/operation.rb', line 34 def steps @result['tracks'].collect {|track| track.name} end |