lib/eco/api/usecases/graphql/helpers/location/command/results.rb in eco-helpers-2.6.4 vs lib/eco/api/usecases/graphql/helpers/location/command/results.rb in eco-helpers-2.7.0
- old
+ new
@@ -6,16 +6,14 @@
@input = input
@response = response
end
def stats
- msg = ''
- first_err = force? ? '' : "(stopped on node: '#{first_errored&.node_id}' - idx: #{first_errored_idx})"
- msg << " • Errored: #{errored.count} #{first_err}\n" if errored?
- last_okay = force? ? '' : "(last node done: '#{last_applied&.node_id}' - idx: #{last_applied_idx})"
- msg << " • Applied: #{errored.count} #{last_okay}\n" if some_applied?
- msg << " • Pending: #{pending.count}\n" if some_pending?
+ msg = ''
+ msg << " • Errored: #{errored.count} #{first_err_str}\n" if errored?
+ msg << " • Applied: #{errored.count} #{last_okay_str}\n" if some_applied?
+ msg << " • Pending: #{pending.count}\n" if some_pending?
msg
end
# Was this configured to force-continue on command error?
def force?
@@ -36,11 +34,11 @@
def error?
!!error
end
def success?
- !error? && results.all? {|r| r.success?}
+ !error? && results.all?(&:success?)
end
def results
@results ||= input_commands.zip(response_results).each_with_object([]) do |(i, r), results|
results << Result.new(i, r)
@@ -62,11 +60,11 @@
def idx(result)
results.index(result)
end
def errored
- @errored ||= results.select {|r| r.error?}
+ @errored ||= results.select(&:error?)
end
def errored?
!errored.empty?
end
@@ -78,19 +76,19 @@
def first_errored_idx
idx(first_errored)
end
def applied
- @applied ||= results.select {|r| r.applied?}
+ @applied ||= results.select(&:applied?)
end
def applied?
- results.all? {|r| r.applied?}
+ results.all?(&:applied?)
end
def some_applied?
- applied.count > 0
+ applied.count.positive?
end
def last_applied
applied.last
end
@@ -98,11 +96,11 @@
def last_applied_idx
idx(last_applied)
end
def pending
- @pending ||= results.select {|r| r.pending?}
+ @pending ||= results.select(&:pending?)
end
def some_pending?
!pending.empty?
end
@@ -119,8 +117,22 @@
input[:commands]
end
def response_results
response&.results || []
+ end
+
+ # First error is relevant only if request was NOT forced to continue.
+ def first_err_str
+ return '' if force?
+ pre_str = 'stopped on node'
+ pre_str = 'first error' unless force?
+ "(#{pre_str}: '#{first_errored&.node_id}' - idx: #{first_errored_idx})"
+ end
+
+ # Last successfully applied is relevant only if request was NOT forced to continue.
+ def last_okay_str
+ return '' if force?
+ "(last node done: '#{last_applied&.node_id}' - idx: #{last_applied_idx})"
end
end
end