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.
-
#target_tree ⇒ Object
Returns the value of attribute target_tree.
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
-
#initialize(target_tree) ⇒ Results
constructor
A new instance of Results.
- #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
Constructor Details
#initialize(target_tree) ⇒ Results
Returns a new instance of Results.
7 8 9 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 7 def initialize(target_tree) @target_tree = target_tree end |
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 |
#target_tree ⇒ Object
Returns the value of attribute target_tree.
5 6 7 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 5 def target_tree @target_tree end |
Instance Method Details
#[](key) ⇒ Object
81 82 83 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 81 def[](key) responses[key] ||= [] end |
#add_response(key, input_unit_response) ⇒ Object
Note:
this captures the latest draft
72 73 74 75 76 77 78 79 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 72 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
143 144 145 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 143 def applied @applied ||= results.select(&:applied?) end |
#applied? ⇒ Boolean
155 156 157 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 155 def applied? results.all?(&:applied?) end |
#applied_commands(with_id_change: false) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 51 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
107 108 109 110 111 112 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 107 def command_results(response = final_response) response = final_response(response) return [] unless response response.results || [] end |
#count ⇒ Object
93 94 95 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 93 def count responses.values.flatten.count end |
#draft_id ⇒ Object
11 12 13 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 11 def draft_id draft&.id end |
#error ⇒ Object
Overal errors (i.e. ID clashes between different structures)
123 124 125 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 123 def error response&.error end |
#error? ⇒ Boolean
Note:
it only accounts for the errors of the final publishing of the draft.
41 42 43 44 45 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 41 def error? return false unless final_response final_response.error? end |
#errored ⇒ Object
139 140 141 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 139 def errored @errored ||= results.select(&:error?) end |
#errored? ⇒ Boolean
151 152 153 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 151 def errored? errored.any? end |
#final_response(response = nil) ⇒ Object
Note:
it receives the final results response (when the draft gets published)
30 31 32 33 34 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 30 def final_response(response = nil) return @response if response.nil? @response = response end |
#final_response? ⇒ Boolean
36 37 38 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 36 def final_response? !final_response.nil? end |
#first_errored ⇒ Object
159 160 161 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 159 def first_errored errored.first end |
#first_errored_idx ⇒ Object
163 164 165 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 163 def first_errored_idx result_idx(first_errored) end |
#input_commands ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 97 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
89 90 91 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 89 def keys responses.keys end |
#last_applied ⇒ Object
171 172 173 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 171 def last_applied applied.last end |
#last_applied_idx ⇒ Object
175 176 177 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 175 def last_applied_idx result_idx(last_applied) end |
#parent_structure ⇒ Object
15 16 17 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 15 def parent_structure draft&.parent_structure || target_tree end |
#pending ⇒ Object
147 148 149 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 147 def pending @pending ||= results.select(&:pending?) end |
#responses ⇒ Object
85 86 87 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 85 def responses @responses ||= {} end |
#result_idx(result) ⇒ Object
def input_idx(input) results.index(input_result(input)) end
135 136 137 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 135 def result_idx(result) results.index(result) end |
#results ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 63 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
167 168 169 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 167 def some_applied? applied.any? end |
#some_pending? ⇒ Boolean
179 180 181 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 179 def some_pending? !pending.empty? end |
#stats ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 114 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
25 26 27 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 25 def structure draft&.structure end |
#structure_id ⇒ Object
Note:
target parent structure id
20 21 22 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 20 def structure_id parent_structure&.id end |
#success? ⇒ Boolean
47 48 49 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 47 def success? !error? end |