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

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

#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

#target_treeObject

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

#appliedObject



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

Returns:

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

#countObject



93
94
95
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 93

def count
  responses.values.flatten.count
end

#draft_idObject



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

def draft_id
  draft&.id
end

#errorObject

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.

Returns:

  • (Boolean)


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

#erroredObject



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

Returns:

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

Returns:

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



159
160
161
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 159

def first_errored
  errored.first
end

#first_errored_idxObject



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_commandsObject



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

#keysObject



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

def keys
  responses.keys
end

#last_appliedObject



171
172
173
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 171

def last_applied
  applied.last
end

#last_applied_idxObject



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_structureObject



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

#pendingObject



147
148
149
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 147

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

#responsesObject



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

#resultsObject



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

Returns:

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

Returns:

  • (Boolean)


179
180
181
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 179

def some_pending?
  !pending.empty?
end

#statsObject



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

#structureObject

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_idObject

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

Returns:

  • (Boolean)


47
48
49
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 47

def success?
  !error?
end