Class: Clomp::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/clomp/operation.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(track_builders: [], options: {}, exec: true) ⇒ self

Constructor for operation object

Parameters:

  • track_builders (Array) (defaults to: [])

    the list of tracks we define

  • options (Hash) (defaults to: {})

    of options to be provided by .[] call/method



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/clomp/operation.rb', line 10

def initialize(track_builders: [], options: {}, exec: true)
  @options          = {}
  @options[:params] = options[:params]
  @options.merge!(options[:immutable_data]) if options[:immutable_data]
  # Setup result object!
  @result = Result.new(
      operation: self,
      tracks:    track_builders || [],
      options:   @options || {}
  )
  
  @executed = []
  @configs  = self.class.setup_configuration
  @output   = get_status
  
  exec_steps! if exec
end

Class Attribute Details

.configsObject

To store and read all the tracks!



70
71
72
# File 'lib/clomp/operation.rb', line 70

def configs
  @configs
end

.track_buildersObject

To store and read all the tracks!



70
71
72
# File 'lib/clomp/operation.rb', line 70

def track_builders
  @track_builders
end

Instance Attribute Details

#configsObject (readonly)

Returns the value of attribute configs.



3
4
5
# File 'lib/clomp/operation.rb', line 3

def configs
  @configs
end

#executedObject (readonly)

Returns the value of attribute executed.



3
4
5
# File 'lib/clomp/operation.rb', line 3

def executed
  @executed
end

#outputObject (readonly)

Returns the value of attribute output.



3
4
5
# File 'lib/clomp/operation.rb', line 3

def output
  @output
end

#resultObject (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: []



133
134
135
136
137
138
139
140
141
# File 'lib/clomp/operation.rb', line 133

def call(mutable_data = {}, immutable_data = {})
  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!



120
121
122
123
124
# File 'lib/clomp/operation.rb', line 120

def failure(track_name, track_options: {}, &block)
  @track_builders ||= []

  @track_builders << build_track(track_name, track_options, 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!



127
128
129
130
131
# File 'lib/clomp/operation.rb', line 127

def finally(track_name, track_options: {}, &block)
  @track_builders ||= []
  
  @track_builders << build_track(track_name, track_options, true, track_for: nil, &block)
end

.method_missing(symbol, *args) ⇒ Object



111
112
113
114
115
116
117
# File 'lib/clomp/operation.rb', line 111

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

Yields:

  • (config)

    to mutate new configuration

Returns:



80
81
82
83
84
85
86
# File 'lib/clomp/operation.rb', line 80

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

Raises:

  • (UnknownOperation)


92
93
94
95
96
97
98
99
100
# File 'lib/clomp/operation.rb', line 92

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_options, :track, track_for: _callable_class, &block)
end

.track(track_name, track_options: {}, &block) ⇒ Object Also known as: set

get track name and options!



103
104
105
106
107
# File 'lib/clomp/operation.rb', line 103

def track(track_name, track_options: {}, &block)
  @track_builders ||= []
  
  @track_builders << build_track(track_name, track_options, true, track_for: nil, &block)
end

Instance Method Details

#exec_steps!Object

Execute all the steps! Execute all the tracks!



33
34
35
# File 'lib/clomp/operation.rb', line 33

def exec_steps!
  Executor[result, @options, _self: self]
end

#executed_stepsObject



41
42
43
# File 'lib/clomp/operation.rb', line 41

def executed_steps
  executed_track_list.collect {|track| track.name }.compact
end

#executed_track_listObject



37
38
39
# File 'lib/clomp/operation.rb', line 37

def executed_track_list
  @result['tracks'].collect {|track| track if track.executed? }.compact
end

#executed_tracksObject



28
29
30
# File 'lib/clomp/operation.rb', line 28

def executed_tracks
  executed_track_list.collect {|executed_track| [executed_track.name, executed_track.type, executed_track.state].join(":") }.join(" --> ")
end

#failedObject Also known as: failed?



50
51
52
# File 'lib/clomp/operation.rb', line 50

def failed
  get_status == 'Failure'
end

#get_statusObject

collect track status



46
47
48
# File 'lib/clomp/operation.rb', line 46

def get_status
  @result['tracks'].collect {|track| track.name if track.failure?}.compact.count.zero? ? 'Success' : 'Failure'
end

#stepsObject

Name of the steps defined in the operation class



63
64
65
# File 'lib/clomp/operation.rb', line 63

def steps
  @result['tracks'].collect {|track| track.name}
end

#successfulObject Also known as: successful?



56
57
58
# File 'lib/clomp/operation.rb', line 56

def successful
  get_status == 'Success'
end