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.
-
#executed ⇒ Object
readonly
Returns the value of attribute executed.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
- .call(mutable_data = {}, immutable_data = {}) ⇒ Object (also: [])
-
.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!.
- .method_missing(symbol, *args) ⇒ Object
-
.setup {|config| ... } ⇒ Configuration
(also: setup_configuration, 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
(also: set)
get track name and options!.
Instance Method Summary collapse
-
#exec_steps! ⇒ Object
Execute all the steps! Execute all the tracks!.
- #executed_steps ⇒ Object
- #executed_track_list ⇒ Object
- #executed_tracks ⇒ Object
- #failed ⇒ Object (also: #failed?)
-
#get_status ⇒ Object
collect track status.
-
#initialize(track_builders: [], options: {}, exec: true) ⇒ self
constructor
Constructor for operation object.
- #prepare_options ⇒ Object
-
#steps ⇒ Object
Name of the steps defined in the operation class.
- #successful ⇒ Object (also: #successful?)
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 23 24 25 26 27 28 |
# File 'lib/clomp/operation.rb', line 10 def initialize(track_builders: [], options: {}, exec: true) @options = Clomp::Option[{params: {}}] @options[:params] = [:params] @options.merge!([:immutable_data]) if [:immutable_data] # Setup result object! @result = Result.new( operation: self, tracks: track_builders || [], options: @options || Option.new ) @executed = [] @configs = self.class.setup_configuration @output = get_status exec_steps! if exec end |
Class Attribute Details
.configs ⇒ Object
To store and read all the tracks!
76 77 78 |
# File 'lib/clomp/operation.rb', line 76 def configs @configs end |
.track_builders ⇒ Object
To store and read all the tracks!
76 77 78 |
# File 'lib/clomp/operation.rb', line 76 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 |
#executed ⇒ Object (readonly)
Returns the value of attribute executed.
3 4 5 |
# File 'lib/clomp/operation.rb', line 3 def executed @executed end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/clomp/operation.rb', line 3 def @options end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
3 4 5 |
# File 'lib/clomp/operation.rb', line 3 def output @output 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
.call(mutable_data = {}, immutable_data = {}) ⇒ Object Also known as: []
139 140 141 142 143 144 145 146 147 |
# File 'lib/clomp/operation.rb', line 139 def call(mutable_data = {}, immutable_data = {}) result = new( track_builders: @track_builders, options: { params: mutable_data || {}, immutable_data: immutable_data || {} }, ).result end |
.failure(track_name, track_options: {}, &block) ⇒ Object
get the track name for the failure case!
126 127 128 129 130 |
# File 'lib/clomp/operation.rb', line 126 def failure(track_name, track_options: {}, &block) @track_builders ||= [] @track_builders << build_track(track_name, , false, 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!
133 134 135 136 137 |
# File 'lib/clomp/operation.rb', line 133 def finally(track_name, track_options: {}, &block) @track_builders ||= [] @track_builders << build_track(track_name, , true, track_for: nil, &block) end |
.method_missing(symbol, *args) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/clomp/operation.rb', line 117 def method_missing(symbol, *args) if self.configuration.custom_step_names.include?(symbol) track(args) else super end end |
.setup {|config| ... } ⇒ Configuration Also known as: setup_configuration, 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
86 87 88 89 90 91 92 |
# File 'lib/clomp/operation.rb', line 86 def setup @configs ||= Configuration.config yield(@configs) if block_given? @configs end |
.share(track_name, from:, track_options: {}, &block) ⇒ Object
Share track from other operation
98 99 100 101 102 103 104 105 106 |
# File 'lib/clomp/operation.rb', line 98 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 Also known as: set
get track name and options!
109 110 111 112 113 |
# File 'lib/clomp/operation.rb', line 109 def track(track_name, track_options: {}, &block) @track_builders ||= [] @track_builders << build_track(track_name, , true, track_for: nil, &block) end |
Instance Method Details
#exec_steps! ⇒ Object
Execute all the steps! Execute all the tracks!
39 40 41 |
# File 'lib/clomp/operation.rb', line 39 def exec_steps! Executor[result, @options, _self: self] end |
#executed_steps ⇒ Object
47 48 49 |
# File 'lib/clomp/operation.rb', line 47 def executed_steps executed_track_list.collect {|track| track.name }.compact end |
#executed_track_list ⇒ Object
43 44 45 |
# File 'lib/clomp/operation.rb', line 43 def executed_track_list @result['tracks'].collect {|track| track if track.executed? }.compact end |
#executed_tracks ⇒ Object
34 35 36 |
# File 'lib/clomp/operation.rb', line 34 def executed_tracks executed_track_list.collect {|executed_track| [executed_track.name, executed_track.type, executed_track.state, executed_track..keys.join(' || ')] }.join(" --> ") end |
#failed ⇒ Object Also known as: failed?
56 57 58 |
# File 'lib/clomp/operation.rb', line 56 def failed get_status == 'Failure' end |
#get_status ⇒ Object
collect track status
52 53 54 |
# File 'lib/clomp/operation.rb', line 52 def get_status @result['tracks'].collect {|track| track.name if track.failure?}.compact.count.zero? ? 'Success' : 'Failure' end |
#prepare_options ⇒ Object
30 31 32 |
# File 'lib/clomp/operation.rb', line 30 def executed_track_list.map {|track| @options.merge!(track.)} end |
#steps ⇒ Object
Name of the steps defined in the operation class
69 70 71 |
# File 'lib/clomp/operation.rb', line 69 def steps @result['tracks'].collect {|track| track.name} end |
#successful ⇒ Object Also known as: successful?
62 63 64 |
# File 'lib/clomp/operation.rb', line 62 def successful get_status == 'Success' end |