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.
-
#executed ⇒ Object
Returns the value of attribute executed.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
-
#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.
Instance Method Summary collapse
-
#exec!(object, options) ⇒ Object
Track#exec! executes the steps defined in the operation class.
- #executed? ⇒ Boolean
-
#initialize(name: (raise Errors::NoTrackProvided), track_options: {}, right: true, track_from: nil, &block) ⇒ Track
constructor
A new instance of Track.
- #left_track? ⇒ Boolean
- #right_track? ⇒ Boolean
- #type ⇒ Object (also: #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: {}, right: true, track_from: nil, &block) ⇒ Track
Returns a new instance of Track.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/clomp/track.rb', line 10 def initialize(name: (raise Errors::NoTrackProvided), track_options: {}, right: true, track_from: nil, &block) @name = name @track_from = track_from @block = block @track_options = @state = 'pending' @error = nil @right = right @left = !@right @executed = false 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 |
#executed ⇒ Object
Returns the value of attribute executed.
6 7 8 |
# File 'lib/clomp/track.rb', line 6 def executed @executed end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
5 6 7 |
# File 'lib/clomp/track.rb', line 5 def left @left end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/clomp/track.rb', line 5 def name @name end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
5 6 7 |
# File 'lib/clomp/track.rb', line 5 def right @right 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 @track_options end |
Instance Method Details
#exec!(object, options) ⇒ Object
Track#exec! executes the steps defined in the operation class
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/clomp/track.rb', line 41 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 success? && @block self.executed = true self rescue => e @error = e. self.executed = false mark_as_failure! self end |
#executed? ⇒ Boolean
22 23 24 |
# File 'lib/clomp/track.rb', line 22 def executed? @executed == true end |
#left_track? ⇒ Boolean
32 33 34 |
# File 'lib/clomp/track.rb', line 32 def left_track? !right_track? end |
#right_track? ⇒ Boolean
36 37 38 |
# File 'lib/clomp/track.rb', line 36 def right_track? @right end |
#type ⇒ Object Also known as: track?
26 27 28 |
# File 'lib/clomp/track.rb', line 26 def type @right ? :right_track : :left_track end |