Class: Clomp::Track
Constant Summary collapse
- VALID_TRACK_TYPES =
I(track failed_track finally catch)
Constants included from CommonStates
CommonStates::FAILURE, CommonStates::PENDING, CommonStates::SUCCESS
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#track_from ⇒ Object
readonly
Returns the value of attribute track_from.
-
#track_options ⇒ Object
readonly
Returns the value of attribute track_options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#exec!(object, options) ⇒ Object
Track#exec! executes the steps defined in the operation class.
-
#initialize(name: (raise Errors::NoTrackProvided), track_options: {}, track_type: VALID_TRACK_TYPES.first, track_from: nil, &block) ⇒ Track
constructor
A new instance of Track.
Methods included from CommonStates
#exception_raised?, #failure?, #mark_as_failure!, #mark_as_success!, #pending?, #success?
Constructor Details
#initialize(name: (raise Errors::NoTrackProvided), track_options: {}, track_type: VALID_TRACK_TYPES.first, track_from: nil, &block) ⇒ Track
Returns a new instance of Track.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/clomp/track.rb', line 9 def initialize(name: (raise Errors::NoTrackProvided), track_options: {}, track_type: VALID_TRACK_TYPES.first, track_from: nil, &block) raise UnknownTrackType, 'Please provide a valid track type' unless VALID_TRACK_TYPES.include?(track_type) @name = name @track_from = track_from @block = block = @type = track_type @state = 'pending' @error = nil end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
5 6 7 |
# File 'lib/clomp/track.rb', line 5 def block @block end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
5 6 7 |
# File 'lib/clomp/track.rb', line 5 def error @error end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/clomp/track.rb', line 5 def name @name end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
5 6 7 |
# File 'lib/clomp/track.rb', line 5 def state @state end |
#track_from ⇒ Object (readonly)
Returns the value of attribute track_from.
5 6 7 |
# File 'lib/clomp/track.rb', line 5 def track_from @track_from end |
#track_options ⇒ Object (readonly)
Returns the value of attribute track_options.
5 6 7 |
# File 'lib/clomp/track.rb', line 5 def end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/clomp/track.rb', line 5 def type @type end |
Instance Method Details
#exec!(object, options) ⇒ Object
Track#exec! executes the steps defined in the operation class
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/clomp/track.rb', line 32 def exec!(object, ) mark_as_failure! # going to execute! set to failure initially if object.method(name.to_sym).arity > 1 mark_as_success! if object.public_send(name.to_sym, , **) != false else mark_as_success! if object.public_send(name.to_sym, ) != false end @block.() if failure? && @block self rescue => e @error = e. mark_as_failure! self end |