Class: Eco::API::UseCases::GraphQL::Helpers::Location::Command::Results

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/api/usecases/graphql/helpers/location/command/results.rb

Overview

Final ressults of the full run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#draftObject

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

#appliedObject



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

Returns:

  • (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

#countObject



88
89
90
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 88

def count
  responses.values.flatten.count
end

#draft_idObject



6
7
8
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 6

def draft_id
  draft&.id
end

#errorObject

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.

Returns:

  • (Boolean)


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

#erroredObject



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

Returns:

  • (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

Returns:

  • (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_erroredObject



154
155
156
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 154

def first_errored
  errored.first
end

#first_errored_idxObject



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_commandsObject



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

#keysObject



84
85
86
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 84

def keys
  responses.keys
end

#last_appliedObject



166
167
168
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 166

def last_applied
  applied.last
end

#last_applied_idxObject



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_structureObject



10
11
12
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 10

def parent_structure
  draft&.parent_structure
end

#pendingObject



142
143
144
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 142

def pending
  @pending ||= results.select(&:pending?)
end

#responsesObject



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

#resultsObject



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

Returns:

  • (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

Returns:

  • (Boolean)


174
175
176
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 174

def some_pending?
  !pending.empty?
end

#statsObject



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

#structureObject

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_idObject

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

Returns:

  • (Boolean)


42
43
44
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 42

def success?
  !error?
end