class Clomp::Operation

Attributes

configs[RW]

To store and read all the tracks!

track_builders[RW]

To store and read all the tracks!

configs[R]
executed[R]
options[R]
output[R]
result[R]

Public Class Methods

[](mutable_data = {}, immutable_data = {})
Alias for: call
call(mutable_data = {}, immutable_data = {}) click to toggle source
# 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
Also aliased as: []
configuration()
Alias for: setup
failure(track_name, track_options: {}, &block) click to toggle source

get the track name for the failure case!

# File lib/clomp/operation.rb, line 126
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) click to toggle source

get the track name for the final step! Only one step will be executed!

# File lib/clomp/operation.rb, line 133
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) click to toggle source
Calls superclass method
# 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
new(track_builders: [], options: {}, exec: true) click to toggle source

Constructor for operation object

@param track_builders [Array] the list of tracks we define @param options [Hash] of options to be provided by .[] call/method @return [self]

# File lib/clomp/operation.rb, line 10
def initialize(track_builders: [], options: {}, exec: true)
  @options          = Clomp::Option[{params: {}}]
  @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 || Option.new
  )
  
  @executed = []
  @configs  = self.class.setup_configuration
  @output   = get_status
  
  exec_steps! if exec

  prepare_options
end
set(track_name, track_options: {}, &block)
Alias for: track
setup() { |configs| ... } click to toggle source

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

@yield [config] to mutate new configuration

@return [Configuration] @config

# File lib/clomp/operation.rb, line 86
def setup
  @configs ||= Configuration.config
  
  yield(@configs) if block_given?
  
  @configs
end
setup_configuration()
Alias for: setup
share(track_name, from:, track_options: {}, &block) click to toggle source

Share track from other operation

# 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_options, :track, track_for: _callable_class, &block)
end
track(track_name, track_options: {}, &block) click to toggle source

get track name and options!

# File lib/clomp/operation.rb, line 109
def track(track_name, track_options: {}, &block)
  @track_builders ||= []
  
  @track_builders << build_track(track_name, track_options, true, track_for: nil, &block)
end
Also aliased as: set

Private Class Methods

build_track(track_name, track_options = {}, track_type = true, track_for: nil, &block) click to toggle source
# File lib/clomp/operation.rb, line 153
def build_track(track_name, track_options = {}, track_type = true, track_for: nil, &block)
  @configs ||= Configuration.new
  
  TrackBuilder[track_name: track_name, track_options: track_options, track_type: track_type, track_for: track_for, &block]
end

Public Instance Methods

exec_steps!() click to toggle source

Execute all the steps! Execute all the tracks!

# File lib/clomp/operation.rb, line 39
def exec_steps!
  Executor[result, @options, _self: self]
end
executed_steps() click to toggle source
# File lib/clomp/operation.rb, line 47
def executed_steps
  executed_track_list.collect {|track| track.name }.compact
end
executed_track_list() click to toggle source
# File lib/clomp/operation.rb, line 43
def executed_track_list
  @result['tracks'].collect {|track| track if track.executed? }.compact
end
executed_tracks() click to toggle source
# 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.options.keys.join(' || ')] }.join(" --> ")
end
failed() click to toggle source
# File lib/clomp/operation.rb, line 56
def failed
  get_status == 'Failure'
end
Also aliased as: failed?
failed?()
Alias for: failed
get_status() click to toggle source

collect track status

# 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() click to toggle source
# File lib/clomp/operation.rb, line 30
def prepare_options
  executed_track_list.map {|track|  @options.merge!(track.options)}
end
steps() click to toggle source

Name of the steps defined in the operation class

# File lib/clomp/operation.rb, line 69
def steps
  @result['tracks'].collect {|track| track.name}
end
successful() click to toggle source
# File lib/clomp/operation.rb, line 62
def successful
  get_status == 'Success'
end
Also aliased as: successful?
successful?()
Alias for: successful