Class: Eco::API::UseCases::GraphQL::Helpers::Location::Command::Results
- Defined in:
- lib/eco/api/usecases/graphql/helpers/location/command/results.rb
Overview
Final ressults of the full run.
Instance Attribute Summary collapse
-
#draft ⇒ Object
Returns the value of attribute draft.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add_response(key, input_unit_response) ⇒ Object
- #applied ⇒ Object
- #applied? ⇒ Boolean
- #applied_commands(with_id_change: false) ⇒ Object
- #command_results(response = final_response) ⇒ Object
- #count ⇒ Object
- #draft_id ⇒ Object
-
#error ⇒ Object
Overal errors (i.e. ID clashes between different structures).
- #error? ⇒ Boolean
- #errored ⇒ Object
- #errored? ⇒ Boolean
- #final_response(response = nil) ⇒ Object
- #final_response? ⇒ Boolean
- #first_errored ⇒ Object
- #first_errored_idx ⇒ Object
- #input_commands ⇒ Object
- #keys ⇒ Object
- #last_applied ⇒ Object
- #last_applied_idx ⇒ Object
- #parent_structure ⇒ Object
- #pending ⇒ Object
- #responses ⇒ Object
-
#result_idx(result) ⇒ Object
def input_idx(input) results.index(input_result(input)) end.
- #results ⇒ Object
- #some_applied? ⇒ Boolean
- #some_pending? ⇒ Boolean
- #stats ⇒ Object
- #structure ⇒ Object
- #structure_id ⇒ Object
- #success? ⇒ Boolean
Instance Attribute Details
#draft ⇒ Object
Returns the value of attribute draft.
4 5 6 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 4 def draft @draft end |
Instance Method Details
#[](key) ⇒ Object
76 77 78 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 76 def[](key) responses[key] ||= [] end |
#add_response(key, input_unit_response) ⇒ Object
Note:
this captures the latest draft
67 68 69 70 71 72 73 74 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 67 def add_response(key, input_unit_response) self[key] << input_unit_response input_unit_response.tap do |iur| next if final_response self.draft = iur.draft end end |
#applied ⇒ Object
138 139 140 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 138 def applied @applied ||= results.select(&:applied?) end |
#applied? ⇒ Boolean
150 151 152 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 150 def applied? results.all?(&:applied?) end |
#applied_commands(with_id_change: false) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 46 def applied_commands(with_id_change: false) results.select(&:applied?).then do |applied| next applied unless with_id_change applied.select do |result| next false unless (command = result.command_result_data) command.keys.include?(:newId) end end end |
#command_results(response = final_response) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 102 def command_results(response = final_response) response = final_response(response) return [] unless response response.results || [] end |
#count ⇒ Object
88 89 90 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 88 def count responses.values.flatten.count end |
#draft_id ⇒ Object
6 7 8 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 6 def draft_id draft&.id end |
#error ⇒ Object
Overal errors (i.e. ID clashes between different structures)
118 119 120 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 118 def error response&.error end |
#error? ⇒ Boolean
Note:
it only accounts for the errors of the final publishing of the draft.
36 37 38 39 40 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 36 def error? return false unless final_response final_response.error? end |
#errored ⇒ Object
134 135 136 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 134 def errored @errored ||= results.select(&:error?) end |
#errored? ⇒ Boolean
146 147 148 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 146 def errored? errored.any? end |
#final_response(response = nil) ⇒ Object
Note:
it receives the final results response (when the draft gets published)
25 26 27 28 29 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 25 def final_response(response = nil) return @response if response.nil? @response = response end |
#final_response? ⇒ Boolean
31 32 33 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 31 def final_response? !final_response.nil? end |
#first_errored ⇒ Object
154 155 156 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 154 def first_errored errored.first end |
#first_errored_idx ⇒ Object
158 159 160 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 158 def first_errored_idx result_idx(first_errored) end |
#input_commands ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 92 def input_commands keys.each_with_object([]) do |key, commands| self[key].each do |input| next unless input.is_a?(InputUnitResponse) commands.concat(input.commands) end end end |
#keys ⇒ Object
84 85 86 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 84 def keys responses.keys end |
#last_applied ⇒ Object
166 167 168 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 166 def last_applied applied.last end |
#last_applied_idx ⇒ Object
170 171 172 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 170 def last_applied_idx result_idx(last_applied) end |
#parent_structure ⇒ Object
10 11 12 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 10 def parent_structure draft&.parent_structure end |
#pending ⇒ Object
142 143 144 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 142 def pending @pending ||= results.select(&:pending?) end |
#responses ⇒ Object
80 81 82 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 80 def responses @responses ||= {} end |
#result_idx(result) ⇒ Object
def input_idx(input) results.index(input_result(input)) end
130 131 132 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 130 def result_idx(result) results.index(result) end |
#results ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 58 def results return [] unless final_response @results ||= input_commands.zip(command_results).each_with_object([]) do |(i, r), results| results << Result.new(i, r) end end |
#some_applied? ⇒ Boolean
162 163 164 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 162 def some_applied? applied.count.positive? end |
#some_pending? ⇒ Boolean
174 175 176 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 174 def some_pending? !pending.empty? end |
#stats ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 109 def stats msg = '' msg << " * Errored: #{errored.count} #{first_err_str}\n" if errored? msg << " * Applied: #{applied.count} #{last_okay_str}\n" if some_applied? msg << " * Pending: #{pending.count}\n" if some_pending? msg end |
#structure ⇒ Object
Note:
the result of the draft
20 21 22 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 20 def structure draft&.structure end |
#structure_id ⇒ Object
Note:
target parent structure id
15 16 17 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 15 def structure_id draft&.structure_id end |
#success? ⇒ Boolean
42 43 44 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 42 def success? !error? end |