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
82 83 84 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 82 def[](key) responses[key] ||= [] end |
#add_response(key, input_unit_response) ⇒ Object
Note:
this captures the latest draft
73 74 75 76 77 78 79 80 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 73 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
144 145 146 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 144 def applied @applied ||= results.select(&:applied?) end |
#applied? ⇒ Boolean
156 157 158 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 156 def applied? results.all?(&:applied?) end |
#applied_commands(with_id_change: false) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# 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) next false unless (command = result.command_input_data) command.keys.include?(:newId) end end end |
#command_results(response = final_response) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 108 def command_results(response = final_response) response = final_response(response) return [] unless response response.results || [] end |
#count ⇒ Object
94 95 96 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 94 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)
124 125 126 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 124 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
140 141 142 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 140 def errored @errored ||= results.select(&:error?) end |
#errored? ⇒ Boolean
152 153 154 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 152 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
160 161 162 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 160 def first_errored errored.first end |
#first_errored_idx ⇒ Object
164 165 166 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 164 def first_errored_idx result_idx(first_errored) end |
#input_commands ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 98 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
90 91 92 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 90 def keys responses.keys end |
#last_applied ⇒ Object
172 173 174 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 172 def last_applied applied.last end |
#last_applied_idx ⇒ Object
176 177 178 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 176 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
148 149 150 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 148 def pending @pending ||= results.select(&:pending?) end |
#responses ⇒ Object
86 87 88 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 86 def responses @responses ||= {} end |
#result_idx(result) ⇒ Object
def input_idx(input) results.index(input_result(input)) end
136 137 138 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 136 def result_idx(result) results.index(result) end |
#results ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 64 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
168 169 170 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 168 def some_applied? applied.any? end |
#some_pending? ⇒ Boolean
180 181 182 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 180 def some_pending? !pending.empty? end |
#stats ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 115 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 |